Problem: You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow.

The only line of the test case contains two integers n and s (1 ≤ n ≤ 10^{18}; 1 ≤ s ≤ 162).

Output

For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s.

Example

Input


5
2 1
1 1
500 4
217871987498122 10
100000000000000001 1


Output


8
0
500
2128012501878
899999999999999999

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1e5 + 1;
const long long INF = 1e9;
const long long LINF = 1e18;
void pra(long long a[], long long n) {
  for (long long i = 0; i < n; i++) cout << a[i] << " ";
  cout << '\n';
}
void prv(vector<long long> &a, long long n) {
  long long i = 0;
  for (long long x : a) {
    i++;
    cout << x << " ";
    if (i == n) break;
  }
  cout << '\n';
}
void prvp(vector<pair<long long, long long>> vp, long long n) {
  long long i = 0;
  for (auto x : vp) {
    i++;
    cout << x.first << " " << x.second << '\n';
    if (i == n) break;
  }
  cout << '\n';
}
long long num(vector<vector<long long>> &v, double val) {
  long long n = v.size();
  long long count = 0;
  for (long long i = 0; i < n; i++) {
    count += lower_bound(v[i].begin(), v[i].end(), val) - v[i].begin();
  }
  return count;
}
long long num(vector<long long> &a) {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cout << "lala" << endl;
  }
  return 1;
}
double num(long long a, long long b, long long c) {
  cout << a << " " << b << " " << c << endl;
  if (a == 100 || b == 100 || c == 100) {
    return 0;
  }
  return ((double)a * (1 + num(a + 1, b, c)) / (a + b + c) +
          (double)b * (1 + num(a, b + 1, c)) / (a + b + c) +
          (double)c / (a + b + c) * (1 + num(a, b, c + 1)));
}
unsigned long long power(unsigned long long x, long long y, long long p) {
  unsigned long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long gcdExtended(long long a, long long b, long long *x, long long *y);
long long modInverse(long long b, long long m) {
  long long x, y;
  long long g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
long long modDivide(long long a, long long b, long long m) {
  a = a % m;
  long long inv = modInverse(b, m);
  if (inv == -1)
    cout << "lala", exit(0);
  else
    return (inv * a) % m;
}
long long gcdExtended(long long a, long long b, long long *x, long long *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  long long x1, y1;
  long long gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
unsigned long long nCrModPFermat(unsigned long long n, long long r,
                                 long long p) {
  if (r == 0) return 1;
  if (r > n) return 0;
  unsigned long long fac[n + 1];
  fac[0] = 1;
  for (long long i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
long long mod(string num, long long a) {
  long long res = 0;
  for (long long i = 0; i < num.length(); i++)
    res = (res * 10 + (long long)num[i] - '0') % a;
  return res;
}
long long largestPower(long long n, long long p) {
  long long x = 0;
  while (n) {
    n /= p;
    x += n;
  }
  return x;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modFact(long long n, long long p) {
  if (n < 0) return 0;
  if (n >= p) return 0;
  long long res = 1;
  bool isPrime[n + 1];
  for (long long i = 2; i * i <= n; i++) {
    if (isPrime[i]) {
      for (long long j = 2 * i; j <= n; j += i) isPrime[j] = 0;
    }
  }
  for (long long i = 2; i <= n; i++) {
    if (isPrime[i]) {
      long long k = largestPower(n, i);
      res = (res * power(i, k, p)) % p;
    }
  }
  return res;
}
long long P = 1e9;
long long mod(long long n) { return (n % P + P) % P; }
long long modM(long long n, long long m) { return ((n % P * m % P) + P) % P; }
long long modA(long long n, long long m) { return ((n % P + m % P) + P) % P; }
long long modS(long long n, long long m) { return ((n % P - m % P) + P) % P; }
unordered_set<long long> uh;
long long V = 1;
struct segtree {
  long long size = 1;
  vector<long long> sums;
  void init(long long n) {
    size = 1;
    while (size < n) size *= 2;
    sums.assign(size * 2, 0);
  }
  void set(long long i, long long v, long long x, long long lx, long long rx) {
    if (rx - lx == 1) {
      sums[x] = v;
      return;
    }
    long long m = (lx + rx) / 2;
    if (i < m) {
      set(i, v, 2 * x + 1, lx, m);
    } else {
      set(i, v, 2 * x + 2, m, rx);
    }
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }
  void set(long long i, long long v) { set(i, v, 0, 0, size); }
  void build(vector<long long> &a, long long x, long long lx, long long rx) {
    if (lx - rx == -1) {
      if (lx < a.size()) {
        sums[x] = a[lx];
      }
      return;
    }
    long long m = (lx + rx) / 2;
    build(a, 2 * x + 1, lx, m);
    build(a, 2 * x + 2, m, rx);
    sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
  }
  void build(vector<long long> &a) { build(a, 0, 0, size); }
  long long find_sum(long long l, long long r, long long x, long long lx,
                     long long rx) {
    if (lx >= r || rx <= l) return 0;
    if (lx >= l && rx <= r) return sums[x];
    long long m = (lx + rx) / 2;
    return find_sum(l, r, 2 * x + 1, lx, m) + find_sum(l, r, 2 * x + 2, m, rx);
  }
  long long find_sum(long long l, long long r) {
    return find_sum(l, r, 0, 0, size);
  }
};
long long val(string &s) {
  long long ans = 0;
  for (long long i = s.length() - 1; i >= 0; i--) {
    ans += (s[i] - '0') * pow(2, (s.length() - 1 - i));
  }
  return ans;
}
void solve() {
  string s;
  cin >> s;
  long long n;
  cin >> n;
  long long l = 0;
  long long ans = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (l + (s[i] - '0') > n) {
      if (l == n) {
        long long j = i - 1;
        while (l == n && j >= 0) {
          l -= (s[j] - '0');
          j--;
        }
        ans = pow(10, s.length() - j - 1);
        ans -= stoll(s.substr(j + 1, s.length() - j - 1));
        break;
      } else {
        ans = pow(10, s.length() - i);
        ans -= stoll(s.substr(i, s.length() - i));
        break;
      }
    }
    l += (s[i] - '0');
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tc;
  cin >> tc;
  for (long long t = 1; t <= tc; t++) {
    solve();
  }
}