Given two vessels, one of which can accommodate a liters of water and the other which can accommodate b liters of water, determine the number of steps required to obtain exactly c liters of water in one of the vessels.

At the beginning both vessels are empty. The following operations are counted as 'steps':


emptying a vessel,
filling a vessel,
pouring water from one vessel to the other, without spilling, until one of the vessels is either full or empty.


Input

An integer t, 1 ≤ t ≤ 100, denoting the number of test cases, followed by t sets of input data, each consisting of three positive integers a (the number of liters the first container can hold), b (the number of liters the second container can hold), and c (the final amount of liters of water one vessel should contain), not larger than 40000, given in separate lines.
Output

For each set of input data, output the minimum number of steps required to obtain c liters, or -1 if this is impossible.

Example

Sample input:
2
5
2
3
2
3
4


Sample output:

2
-1
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def solve(a,b,c):
    if c==0:return 0
    if c==a or c==b:return 1
    if a>b:a,b=b,a
    if c>b:return -1
    if c==b-a:return 2
    d=gcd(a,b)
    if d!=1:
        if c%d:return -1
        a/=d;b/=d;c/=d;
    q=b/a
    rk=0
    r=a
    while True:
        if c==r:return rk
        rk+=2
        if c==b-r:return rk
        x=r;y=b-r
        for k in range(1,q+2):
            x+=a
            y=b-x
            rk+=2        
            if y<0:
                r=-y
                break
            if c==x or c==y:return rk

t=int(raw_input())
for _ in range(t):
    a=int(raw_input())
    b=int(raw_input())
    c=int(raw_input())
    print solve(a,b,c)