#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e8 + 7;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int digit[30], pos;
int get(long long x) {
  pos = 0;
  int sum = 0;
  while (x) {
    sum += (digit[pos++] = x % 10);
    x /= 10;
  }
  digit[pos] = 0;
  return sum;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n = read(), s = read();
    int sum = get(n);
    if (sum <= s) {
      cout << "0" << endl;
      continue;
    }
    long long ans = 0, lstsum = sum, base = 1;
    for (int i = 1; i <= pos; ++i) {
      long long tsum = lstsum - digit[i - 1] + 1;
      ++digit[i];
      ans += (10 - digit[i - 1]) * base;
      lstsum = tsum;
      base *= 10;
      if (tsum <= s) {
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
