#include <bits/stdc++.h>
using namespace std;
int f(string n) {
  int ans = 0;
  for (int i = 0; i < (int)n.size(); i++) ans += n[i] - '0';
  return ans;
}
void chng(int i, string &n) {
  if (i == -1) {
    n = "1" + n;
    return;
  }
  while (i >= 0 && n[i] == '9') {
    n[i] = '0';
    i--;
  }
  if (i == -1)
    n = "1" + n;
  else
    n[i] = char(1 + int(n[i]));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    long long s, i, ans = 0, t = 1;
    string n;
    cin >> n >> s;
    i = (int)n.size() - 1;
    while (f(n) > s && i >= 0) {
      if (n[i] != '0') {
        ans += (10 - (n[i] - '0')) * t;
        n[i] = '0';
        chng(i - 1, n);
      }
      t *= 10;
      i--;
    }
    cout << ans << "\n";
  }
}
