#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T, n, m, k, p, q, i, j, s, x, y;
  cin >> T;
  while (T--) {
    cin >> n >> s;
    x = 0;
    vector<long long int> a;
    q = 0;
    p = n;
    while (n > 0) {
      j = n % 10;
      q = q + j;
      a.push_back(j);
      n = n / 10;
    }
    m = a.size();
    if (q <= s) {
      cout << "0" << endl;
      continue;
    }
    for (i = 0; i <= m - 1; i++) {
      if (q >= s) {
        x = 1;
        q = q - a[i];
        a[i] = 0;
      } else {
        break;
      }
    }
    if (i == m) {
      a.push_back(1);
      reverse(a.begin(), a.end());
      y = 0;
      for (i = 0; i <= a.size() - 1; i++) {
        y = (10 * y) + a[i];
      }
      cout << y - p << endl;
      continue;
    }
    if (x == 1) {
      a[i]++;
    }
    reverse(a.begin(), a.end());
    y = 0;
    for (i = 0; i <= a.size() - 1; i++) {
      y = (10 * y) + a[i];
    }
    cout << y - p << endl;
  }
}
