#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool customCompare(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first < b.first;
}
long long calcSum(long long n) {
  long long sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
void solve() {
  long long n, s;
  cin >> n >> s;
  long long sum = calcSum(n);
  if (sum <= s) {
    cout << "0\n";
    return;
  }
  long long x = 1, ans = 0;
  while (true) {
    if (calcSum(n) <= s) {
      cout << ans << endl;
      break;
    }
    long long y = n % 10;
    ans += x * (10 - y);
    x *= 10;
    n /= 10;
    n += 1;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
