逆序数

Time Limit: 1000MS

Memory Limit: 65535K

Description

Give you N(0<N<=1000) groups of strings.Each group has 2 strings.Now you are required to sort these groups by the first string ascending order. If first strings are the same, then you should sort them by  the second string descending order.The right order of strings is alphabetical.The length of one string will not be exceed 50.

To make it harder, I want you compute the Inverse number(Do not know it? Find it in Hint).

Input

The Input consists of mulitiple cases.

In each case, the first line contains an integer N(0<N<=1000).

Then follows N lines. Each line contains two string. The strings consists of only English letters(case-sensitive).

Output

output the inverse number a line for each cases.

Sample Input

3
abc cba
cba abc
abc aac
5
abcd aaaa
acbdef aaaa
Abcdek ccccc
aBde ccccc
acbdef AAA

Sample Output

1
4

Hint

Hint
Inverse number:在一个排列中，如果一对数的前后位置与大小顺序相反，即前面的数大于后面的数，那么它们就称为一个逆序。一个排列中逆序的总数就称为这个排列的逆序数。也就说，对于n个不同的元素，先规定各元素之间有一个标准次序（例如n个 不同的自然数，可规定从小到大为标准次序），于是在这n个元素的任一排列中，当某两个元素的先后次序与标准次序不同时，就说有1个逆序。一个排列中所有逆序总数叫做这个排列的逆序数。

Absoult