#include <bits/stdc++.h>
using namespace std;
long long int power(int i) {
  long long int x = 1;
  while (i--) {
    x = x * 10;
  }
  return x;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n, p;
    int s;
    cin >> n >> s;
    p = n;
    int a[19], b[19];
    for (int i = 0; i < 19; i++) {
      a[i] = n / power(18 - i);
      n = n - a[i] * power(18 - i);
    }
    int x = 0;
    for (int i = 0; i < 19; i++) {
      x = x + a[i];
    }
    if (s >= x)
      cout << 0 << endl;
    else {
      int i = 0;
      for (i = 0; i < 19; i++) {
        if (s > a[i]) {
          s = s - a[i];
        } else
          break;
      }
      int j;
      int c[19 - i];
      for (j = 0; j < 19 - i; j++) {
        if (a[18 - j] != 0) break;
        c[j] = a[18 - j];
      }
      c[j] = 10 - a[18 - j];
      int t = j + 1;
      for (int p = 17 - j; p >= i; p--) {
        c[t] = 9 - a[p];
        t++;
      }
      int initial0 = 0;
      for (int f = 18 - i; f >= 0; f--) {
        if (c[f] != 0)
          break;
        else
          initial0++;
      }
      for (int f = 18 - i - initial0; f >= 0; f--) {
        cout << c[f];
      }
      cout << endl;
    }
  }
}
