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.
//package org.javadov.codeforces.contest412;

import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by asgar on 2/21/17.
 */

public class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
        int x = in.nextInt();
        int y = in.nextInt();
        int p = in.nextInt();
        int q = in.nextInt();

        Rational current = new Rational(x, y);
        Rational target = new Rational(p, q);

        if (current.compareTo(target) == 0) {
            out.println(0);
            return;
        }
        if ((current.compareTo(target) < 0 && target.compareTo(new Rational(1, 1)) == 0) ||
                (current.compareTo(target) > 0 && target.compareTo(new Rational(0, 1)) == 0)) {
                out.println(-1);
                return;
            }
        int k = (y-x + q-p - 1) / (q-p);
        k = Math.max(k, (x + p-1)/p);
        long t = q * (long) k - y;
        out.println(t);
        return;
    }

    static class Rational implements Comparable<Rational> {
        int up, down;

        public Rational(int up, int down) {
            this.up = up;
            this.down = down;
            if (down < 0) {
                this.up = -up;
                this.down = -down;
            }
        }

        @Override
        public int compareTo(Rational o) {
            return Long.compare(up * 1L * o.down, down * 1L * o.up);
        }
    }
    public static void main(String[] args) throws IOException {
        try (InputReader reader = new InputReader(System.in);
             PrintWriter writer = new PrintWriter(System.out)) {
            TaskC solver = new TaskC();
            int testCount = reader.nextInt();
            for (int i = 0; i < testCount; i++) {
                solver.solve(i, reader, writer);
            }
            writer.flush();
        }
    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() throws IOException {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                String line = readLine();
                if (line == null)
                    return null;
                tokenizer = new StringTokenizer(line);
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() throws IOException {
            return Integer.valueOf(next());
        }

        public Long nextLong() throws IOException {
            return Long.valueOf(next());
        }

        public int[] readIntArray (int size) throws IOException {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }
    }

    static class FastWriter extends PrintWriter {
        public FastWriter(OutputStream outputStream) {
            super(outputStream);
        }
    }
}


