#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int t;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    long long int n, s;
    cin >> n >> s;
    long long int x = 0;
    long long int q = n;
    while (1) {
      long long int a = 0;
      long long int f = q;
      while (f != 0) {
        a = a + f % 10;
        f /= 10;
      }
      if (a <= s) {
        cout << x << endl;
        break;
      } else {
        for (long long int j = 1;;) {
          long long int z = pow(10, j);
          if (q % (z) != 0) {
            q = (q / (z) + 1) * (z);
            x = q - n;
            break;
          } else
            j++;
        }
      }
    }
  }
}
