Buckets A and B hold a and b liters of water when full. Neither bucket has measuring lines, so you cannot tell how much water is inside unless the bucket is empty or full. Bucket A starts with x liters and bucket B starts with y liters. Next to them is a reservoir that holds an unlimited amount of water.
Because the buckets have no measuring lines, keeping the exact contents of both buckets known leaves you only these six operations.
A pair of integers Oi=(si,ti) is called a target amount. The target amount Oi is achievable from (s,t) if some sequence of zero or more of the operations above turns buckets holding exactly s and t liters into buckets holding exactly si and ti liters.
You are given target amounts O1,O2,…,On. Find the longest subsequence Oi1,Oi2,…,Oil with i1<i2<⋯<il such that each one is achievable from the previous one. The subsequence does not have to be consecutive, so O1,O4,O6,O8 is allowed when n is large enough, and the previous one for Oi1 is the starting pair (x,y). In other words, you make the first target amount from the starting pair using only the operations above, then the second from the first, and so on. Print the length l of the longest such subsequence.
The first line has the number of test cases T. Each test case starts with a line of five integers a, b, x, y, and n (1≤a,b≤109, 0≤x≤a, 0≤y≤b, 1≤n≤200000), where a and b are the capacities of A and B, x and y are the starting amounts of water in A and B, and n is the number of target amounts. Each of the next n lines has a target amount as two integers s and t (0≤s≤a, 0≤t≤b), the amount of water to be held in A and in B.
Print exactly one line for each test case. The line holds the length of the longest subsequence defined above. Print 0 when no target amount is achievable from (x,y).