You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y.

Your favorite rational number in the [0;1] range is p / q. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be p / q?

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.

Each of the next t lines contains four integers x, y, p and q (0 ≤ x ≤ y ≤ 109; 0 ≤ p ≤ q ≤ 109; y > 0; q > 0).

It is guaranteed that p / q is an irreducible fraction.

Hacks. For hacks, an additional constraint of t ≤ 5 must be met.

Output

For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.

Example

Input

4
3 10 1 2
7 14 3 8
20 70 2 7
5 6 1 1


Output

4
10
0
-1

Note

In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2.

In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8.

In the third example, there is no need to make any new submissions. Your success rate is already equal to 20 / 70, or 2 / 7.

In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to 1.
import java.io.*;
    import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;

 
    

     
     
     public class Main {
    	public static InputReader in;
        public static PrintWriter pw;
     
     
     
    	public static void main(String args[]) {
    		new Thread(null, new Runnable() {
                public void run() {
                    try{
                        solve();
                    }
                    catch(Exception e){
                        e.printStackTrace();
                    }
                }
            }, "1", 1 << 26).start();
        }
    	static ArrayList<Integer> g[];
    	static ArrayList<Integer> h[];
    	static boolean visited[];
    	static boolean parent[];
    	static int par[];
    	static int degree[];
    	static int edjes=0;
    	static int start=-1;
    	static int end=-1;
    	static int Total=0;
    	static int time1[];
    	static int time2[];
    	static int glob=0;
    	static long ans[]=new long[1000000];
    	static boolean vis2[][];
    	//static long sum1=0;
    	//static long val[];
        static ArrayList<Integer> levels[];
        static int max=0;
        static int lev=1;
        static ArrayList<Integer> nodes[];
        static ArrayList<Integer> values[];
        static int depth[];
        static boolean found=false;
       // static long sm[];
        static int sum1=0;
        static int pre[][];
        static int subtree[];
       static  int cnt=0;
       static  HashMap<String,Integer> hm;
       static int sm[];
       static int prime[];
       static long mul[];
       static long d[]=new long[1000000];
       static int tot=0;
       static long highest=(long)1e9;
       static boolean bit=false;
        static Stack<Integer> tt=new Stack();
       static HashSet<String> set=new HashSet<String>();
 	   static long fact[];
 	   static long MOD=1000000007;
        public static void solve() throws FileNotFoundException{
    		
    	
    		 in = new InputReader(System.in);
    		 pw = new PrintWriter(System.out);    
             int t=in.nextInt();
             while(t-->0)
             {
            	 long x=in.nextLong();
            	 long y=in.nextLong();
            	 long p=in.nextLong();
            	 long q=in.nextLong();
            	 long low=1;
            	 long high=(long)2e9;
            	 long ans=-1;
            	 while(low<=high)
            	 {
            		 long mid=(low+high)/2;
            		 long x1=mid*p;
            		 long x2=mid*q;
            		 long up=(x1-x);
            		 long down=(x2-y);
            		 if(x1>=x&&x2>=y&&up<=down)
            		 {
            			 ans=mid;
            			 high=mid-1;
            		 }
            		 else
            		 {
            			 low=mid+1;
            		 }
            	 }
            	 if(ans==-1)
            		 System.out.println(ans);
            	 else
            	 System.out.println((ans*q)-y);
             }
             
        
        }
        
        static long ncr(long a, long b){
			if(b>a || b<0) return 0;
			long f = (fact[(int) a]*modInverse(((fact[(int) b]*fact[(int) (a-b)])%MOD), MOD))%MOD;
			return f;
		}
		static long modInverse(long a, long mOD2){
            return  power(a, mOD2-2, mOD2);
}
static long power(long x, long y, long m)
{
    if (y == 0)
        return 1;
    long p = power(x, y/2, m) % m;
    p = (p * p) % m;
 
    return (y%2 == 0)? p : (x * p) % m;
}

        public static long gcd(long x, long y) {
    		if (x == 0)
    			return y;
    		else
    			return gcd( y % x,x);
    	}	
        public static long power(long a,long b)
		{
			long result=1;
			while(b>0)
			{
				if(b%2==1)
					result*=a;
				a=a*a;
				b/=2;
			}
			return result;
		}
        static class Pair implements Comparable<Pair>{
        	int a;
        		int b;
        	//	int c;
        		//int index;
        		Pair(int a,int b){
        	     	this.a=a;
        			this.b=b;
               //     this.c=c;        			
        		}
        		@Override
        		public int compareTo(Pair o) {
                      if(o.b>this.b)
                    	  return 1;
                      else
                    	  return -1;
        		}
        				
        	}
    	static class InputReader {
     
    		private InputStream stream;
    		private byte[] buf = new byte[8192];
    		private int curChar, snumChars;
    		private SpaceCharFilter filter;
     
    		public InputReader(InputStream stream) {
    			this.stream = stream;
    		}
     
    		public int snext() {
    			if (snumChars == -1)
    				throw new InputMismatchException();
    			if (curChar >= snumChars) {
    				curChar = 0;
    				try {
    					snumChars = stream.read(buf);
    				} catch (IOException e) {
    					throw new InputMismatchException();
    				}
    				if (snumChars <= 0)
    					return -1;
    			}
    			return buf[curChar++];
    		}
     
    		public   int nextInt() {
    			int c = snext();
    			while (isSpaceChar(c))
    				c = snext();
    			int sgn = 1;
    			if (c == '-') {
    				sgn = -1;
    				c = snext();
    			}
    			int res = 0;
    			do {
    				if (c < '0' || c > '9')
    					throw new InputMismatchException();
    				res *= 10;
    				res += c - '0';
    				c = snext();
    			} while (!isSpaceChar(c));
    			return res * sgn;
    		}
     
    		public long nextLong() {
    			int c = snext();
    			while (isSpaceChar(c))
    				c = snext();
    			int sgn = 1;
    			if (c == '-') {
    				sgn = -1;
    				c = snext();
    			}
    			long res = 0;
    			do {
    				if (c < '0' || c > '9')
    					throw new InputMismatchException();
    				res *= 10;
    				res += c - '0';
    				c = snext();
    			} while (!isSpaceChar(c));
    			return res * sgn;
    		}
     
    		public int[] nextIntArray(int n) {
    			int a[] = new int[n];
    			for (int i = 0; i < n; i++)
    				a[i] = nextInt();
    			return a;
    		}
     
    		public String readString() {
    			int c = snext();
    			while (isSpaceChar(c))
    				c = snext();
    			StringBuilder res = new StringBuilder();
    			do {
    				res.appendCodePoint(c);
    				c = snext();
    			} while (!isSpaceChar(c));
    			return res.toString();
    		}
     
    		public boolean isSpaceChar(int c) {
    			if (filter != null)
    				return filter.isSpaceChar(c);
    			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    		}
     
    		public interface SpaceCharFilter {
    			public boolean isSpaceChar(int ch);
    		}
    	}
    }