#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000000 + 7;
const long long int N = 10000000 + 6;
string lltst(long long int n) {
  string st = "";
  while (n > 0) {
    st.push_back((n % 10) + '0');
    n /= 10;
  }
  reverse(st.begin(), st.end());
  return st;
}
long long int stll(string st) {
  long long int n = 0;
  long long int po = 1;
  for (int j = st.size() - 1; j >= 0; j--) {
    n = (st[j] - '0') * po + n;
    po = po * 10;
  }
  return n;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int temp = n;
    long long int sum = 0;
    while (n > 0) {
      int r = n % 10;
      sum += r;
      n /= 10;
    }
    if (sum <= k) {
      cout << 0 << '\n';
      continue;
    }
    string st = lltst(temp);
    int j = -1;
    int curr = 0;
    long long int rem = sum - k;
    for (int i = st.size() - 1; i >= 0; i--) {
      curr = curr + st[i] - '0';
      if (curr > rem && i - 1 >= 0 && st[i - 1] != '9') {
        j = i;
        break;
      }
    }
    if (j - 1 <= -1) {
      int l = st.size();
      string str = "1";
      while (l--) str.push_back('0');
      long long int big = stll(str);
      long long int small = stll(st);
      cout << big - small << '\n';
    } else {
      string str = "";
      for (int i = 0; i < st.size(); i++) {
        if (i < j - 1)
          str.push_back(st[i]);
        else if (i == j - 1)
          str.push_back(st[i] + 1);
        else
          str.push_back('0');
      }
      long long int big = stll(str);
      long long int small = stll(st);
      cout << big - small << '\n';
    }
  }
  return 0;
}
