You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.

Recall that y mod z is the remainder of the division of y by z. For example, 5 mod 3 = 2, 7 mod 8 = 7, 9 mod 4 = 1, 9 mod 9 = 0.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. Then the test cases follow.

The first line of each test case contains three integers a, b and q (1 ≤ a, b ≤ 200; 1 ≤ q ≤ 500).

Then q lines follow, each containing two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}) for the corresponding query.

Output

For each test case, print q integers — the answers to the queries of this test case in the order they appear.

Example

Input


2
4 6 5
1 1
1 3
1 5
1 7
1 9
7 10 2
7 8
100 200


Output


0 0 0 2 4 
0 91 
import sys, math
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def getInts():
    return [int(s) for s in input().split()]

def getInt():
    return int(input())

def getStrs():
    return [s for s in input().split()]

def getStr():
    return input()

def listStr():
    return list(input())

import collections as col
import math

def solve():
    #in our range, we're interested in (up to a maximum of) a*b numbers, after which the pattern will recur
    #so we calculate the answer for the range L <= X < L+a*b, storing the prefix counts, and then add on the required number of multiples, plus the final prefix
    A, B, Q = getInts()
    ans = []
    prefix = []
    curr_num = 0
    for x in range(A*B):
        if (x % A) % B != (x % B) % A:
            curr_num += 1
        prefix.append(curr_num)
    for q in range(Q):
        L, R = getInts()
        whole = (R-L+1)//(A*B)
        extra = (R-L+1)%(A*B)
        #curr_num*whole takes us to L % A*B not inclusive. Suppose R % A*B < L % A*B
        add_on = 0
        R %= (A*B)
        L %= (A*B)
        if extra:
            if R >= L:
                add_on = prefix[R]-(prefix[L-1] if L > 0 else 0)
            else:
                add_on = curr_num - prefix[L-1] + prefix[R]
        # ans.append(curr_num*whole+add_on)
        # extra numbers begin at L % (A*B) and end at R % (A*B)
        # suppose A*B == 12
        # [0,1,2,3,4,5,6,7,8,9,10,11]
        # now suppose L = 3, R = 7
        # we need pref[R]-(pref[L-1] if L > 0 else 0)
        
        # what if L = 7, R = 3
        # we need 7-11 and 0-3
        # curr_num - pref[L-1] + pref[R]
        ans.append(curr_num*whole+add_on)
    print(*ans)
    return
    
    
for t in range(getInt()):
    solve()
