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.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
 
public class Tree
        implements Runnable{
 
    	static LinkedList <Integer> adj[];

    
    static void Check2(int n){
        adj=new LinkedList[n+1];
        for(int i=0;i<=n;i++){
            adj[i]=new LinkedList();
        }
        
    }
    static void add(int i,int j){
       // if(!adj[i].contains(j))
        adj[i].add(j);
   // if(!adj[j].contains(i))
        adj[j].add(i);
        
     //   adj[j].add(i);
        
    }

    
     public void run(){
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        //Scanner in=new Scanner(System.in);
    InputReader in=new InputReader(System.in);		
		PrintWriter w=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 l=0;
         long r=(long)(1e9);
         long ans=-1;
         while(l<=r)
         {
             long mid=(l+r)/2;
             
             long d=p*mid-x;
             long f=q*mid-y-d;
             if(d>=0&&f>=0)
             {
                 ans=mid;
                 r=mid-1;
             }
             else{
                 l=mid+1;
             }
             
             
             
             
             
             
         }
         
   //      w.println(ans);
         if(ans!=-1)
        w.println(q*ans-y); 
         else
             w.println(-1);
         }
         
		 w.close();
        
           
    }
    
 
      static void dfs(int i,int v[]){
        if(v[i]==1){
            return ;
        }
        else{
            
            v[i]=1;
            Iterator <Integer>p=adj[i].iterator();
            while(p.hasNext()){
                 Integer ne=p.next();
                
                    
                    
              dfs(ne,v);
     //          
       //        System.out.println(q+" "+i);
            //System.out.println(i+" "+max1+" "+max2);
            }
            
            
            
            
            
        }
        
        
    }
     class node implements Comparable <node>{
        
        int y;
        int val;
        
        node(int a,int b){
            
            y=a;
            val=b;
            
        }
        
        public int compareTo(node b)
        {
            
           if(this.y!=b.y){
               return this.y-b.y;
           } 
           else{
               return this.val-b.val;
           }
            
        }

      
        
    }
  
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		
		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}
		
		public int read()
		{
			if (numChars==-1) 
				throw new InputMismatchException();
			
			if (curChar >= numChars)
			{
				curChar = 0;
				try 
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				
				if(numChars <= 0)				
					return -1;
			}
			return buf[curChar++];
		}
	 
		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();
			
			while(isSpaceChar(c)) 
				c = read();
			
			int sgn = 1;
			
			if (c == '-') 
			{
				sgn = -1;
				c = read();
			}
			
			int res = 0;
			do 
			{
				if(c<'0'||c>'9') 
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c)); 
			
			return res * sgn;
		}
		
		public long nextLong() 
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') 
			{
				sgn = -1;
				c = read();
			}
			long res = 0;
			
			do 
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}
		
		public double nextDouble() 
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') 
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') 
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') 
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) 
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
		
		public String readString() 
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do 
			{
				res.appendCodePoint(c);
				c = read();
			} 
			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 String next() 
		{
			return readString();
		}
		
		public interface SpaceCharFilter 
		{
			public boolean isSpaceChar(int ch);
		}
	}
	  public static void main(String[] args) throws Exception { 
    new Thread(null, new Tree(), "Check2", 1<<26).start();// to increse stack size in java 
  }
    
}
