#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int N = 200043;
const long long int MOD = 1000000007;
long long int add(long long int x, long long int y) {
  x = ((x % MOD) + (y % MOD)) % MOD;
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
  return x;
}
long long int mul(long long int x, long long int y) {
  return ((x % MOD) * (y % MOD)) % MOD;
}
long long int binpow(long long int x, long long int y) {
  long long int z = 1;
  while (y) {
    if (y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
long long int inv(long long int x) { return binpow(x, MOD - 2); }
long long int divide(long long int x, long long int y) {
  return mul(x, inv(y));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, i, j;
  cin >> t;
  while (t--) {
    long long int n, s, temp;
    cin >> n >> s;
    temp = n;
    long long int ctr = 0;
    vector<long long int> ar;
    while (temp) {
      ar.push_back(temp % 10);
      ctr += temp % 10;
      temp = temp / 10;
    }
    if (ctr <= s)
      cout << 0 << endl;
    else {
      vector<long long int> ans;
      long long int carry = 0;
      for (i = 0; i < ar.size(); i++) {
        if (ctr <= s) break;
        if (ar[i] == 0 && carry == 0) {
          ans.push_back(0);
          continue;
        }
        ans.push_back(10 - ar[i]);
        carry = 1;
        ctr = ctr - ar[i] + 1;
        if (i + 1 < ar.size())
          ar[i + 1]++;
        else
          ar.push_back(1);
      }
      vector<int> fans;
      long long int ctr = 0;
      reverse(ans.begin(), ans.end());
      for (i = 0; i < ans.size(); i++) {
        if (ans[i] == 0 && ctr == 0) continue;
        cout << ans[i];
        ctr = 1;
      }
      cout << endl;
    }
  }
}
