#include <bits/stdc++.h>
using namespace std;
int sumDigits(long long nn) {
  int sum = 0;
  while (nn != 0) {
    sum += nn % 10;
    nn = floor(nn / 10);
  }
  return sum;
}
int main() {
  int t, s;
  cin >> t;
  size_t nLen;
  long long n;
  while (t--) {
    cin >> n >> s;
    if (sumDigits(n) <= s) {
      cout << "0" << endl;
      continue;
    }
    string nStr = to_string(n);
    nLen = nStr.size();
    int pSum = 0;
    unsigned int j = 0;
    while (pSum < s && j < nLen) {
      pSum += nStr[j] - '0';
      ++j;
    }
    string strSuffix = nStr.substr(j - 1);
    long long nSuffix;
    if (strSuffix.empty())
      nSuffix = 0.0;
    else
      nSuffix = stoll(strSuffix);
    long long pow10 = (long long)pow(10.0, nLen - j + 1);
    cout << fixed << (long long)(pow10 - nSuffix) << endl;
  }
}
