#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f * x;
}
long long ans;
int mts[20];
int main() {
  int t = read();
  while (t--) {
    long long a = read(), as = 0, i;
    int s = read();
    int nw = 0;
    for (i = 1;; ++i) {
      if (!a) break;
      nw += mts[i] = a % 10;
      a /= 10;
    }
    i = 1;
    int pos = 1;
    while (nw > s) {
      nw -= mts[pos];
      nw++;
      as += i * (10 - mts[pos]);
      pos++;
      mts[pos]++;
      i *= 10;
    }
    cout << as << '\n';
  }
  return 0;
}
