#include <bits/stdc++.h>
using namespace std;
long long modPower(long long num, long long r) {
  if (r == 0) return 1;
  if (r == 1) return num % 1000000007;
  long long ans = modPower(num, r / 2) % 1000000007;
  if (r % 2 == 0) {
    return (ans * ans) % 1000000007;
  }
  return (((ans * ans) % 1000000007) * num) % 1000000007;
}
long long nCr(long long n, long long r) {
  long long res = 1;
  if (r > n - r) {
    r = n - r;
  }
  for (long long i = 0; i < r; i++) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int pos(int a) {
  if (a < 0)
    return (-1) * a;
  else
    return a;
}
unsigned long long highestPowerof2(unsigned long long n) {
  unsigned long long p = (unsigned long long)log2(n);
  return (unsigned long long)pow(2, p);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<int> fprint(vector<int> A, int n) {
  vector<int> fprint;
  for (int i = 0; i < n - 1; i++) {
    fprint.push_back(A[i] + A[i + 1]);
  }
  sort(fprint.begin(), fprint.end());
  return fprint;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long grr;
  cin >> grr;
  while (grr--) {
    long long count = 0;
    long long n, s;
    cin >> n >> s;
    long long c = n, rev = 0;
    long long x = 10;
    long long sum = 0, sum2 = 0, len = 0;
    while (c > 0) {
      sum += c % 10;
      rev = rev * 10 + c % 10;
      len++;
      c = c / 10;
    }
    if (sum <= s)
      cout << 0 << "\n";
    else {
      sum2 = 0;
      while (sum2 + rev % 10 < s && rev > 0) {
        count++;
        sum2 += rev % 10;
        rev /= 10;
      }
      long long x = len - count, y = 1;
      while (x--) {
        y *= 10;
      }
      n = n % y;
      x = 10;
      while (n / x != 0) {
        x *= 10;
      }
      cout << x - n << "\n";
    }
  }
}
