HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.

One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read some file.

Find the time need to read file split to *n* fragments. The *i*-th sector contains the *f*<sub class="lower-index">*i*</sub>-th fragment of the file (1 ≤ *f*<sub class="lower-index">*i*</sub> ≤ *n*). Note different sectors contains the different fragments. At the start the magnetic head is in the position that contains the first fragment. The file are reading in the following manner: at first the first fragment is read, then the magnetic head moves to the sector that contains the second fragment, then the second fragment is read and so on until the *n*-th fragment is read. The fragments are read in the order from the first to the *n*-th.

It takes |*a* - *b*| time units to move the magnetic head from the sector *a* to the sector *b*. Reading a fragment takes no time.
The first line contains a positive integer *n* (1 ≤ *n* ≤ 2·10<sup class="upper-index">5</sup>) — the number of fragments.

The second line contains *n* different integers *f*<sub class="lower-index">*i*</sub> (1 ≤ *f*<sub class="lower-index">*i*</sub> ≤ *n*) — the number of the fragment written in the *i*-th sector.
In the second example the head moves in the following way:
 -  1-&gt;2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units -  2-&gt;3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units -  3-&gt;4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time units -  4-&gt;5 means movement from the sector 4 to the sector 3, i.e. it takes 1 time units 
So the answer to the second example is 4 + 3 + 2 + 1 = 10.
3
3 1 2
3
5
1 3 5 4 2
10
1
1
0
1
1
0
1
1
0
10
8 2 10 3 4 6 1 7 9 5
40
10
1 2 3 4 5 6 7 8 9 10
9
10
1 3 5 7 9 10 8 6 4 2
45
100
11 9 35 34 51 74 16 67 26 21 14 80 84 79 7 61 28 3 53 43 42 5 56 36 69 30 22 88 1 27 65 91 46 31 59 50 17 96 25 18 64 55 78 2 63 24 95 48 93 13 38 76 89 94 15 90 45 81 52 87 83 73 44 49 23 82 85 75 86 33 47 19 58 97 37 20 40 10 92 4 6 68 77 54 71 12 62 60 100 39 41 99 72 29 57 8 70 32 66 98
3580
100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
99
100
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2
4950
psum = [[0] * 18 for _ in range(2 * 10 ** 5 + 1)]
for i in range(1, 2 * 10 ** 5 + 1):
    for j in range(18):
        psum[i][j] = psum[i - 1][j] + (i >> j & 1)  # &1하는 이유는 다른 비트를 유효하게 하지 않기 위해서


tc = int(input())
for _ in range(tc):
    L, R = map(int, input().split())

    max_value = 0
    for i in range(18):
        max_value = max(max_value, psum[R][i] - psum[L - 1][i])

    print((R - L + 1) - max_value)
