#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using db = double;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
const int inf = 0x3f3f3f3f;
const int rinf = 0xc0c0c0c0;
const LL MOD = 1e9 + 7;
const LL LMAX = 0x7fffffffffffffff;
const LL LMIN = 0x8000000000000000;
using std::cin;
using std::cout;
using std::endl;
using std::vector;
template <typename T>
void print(vector<vector<T>> a) {
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < a[i].size(); ++j)
      cout << a[i][j] << (j == ((int)a[i].size()) - 1 ? '\n' : ' ');
  }
}
template <typename T>
void print(T *a, int len) {
  for (int i = 0; i < len; ++i) cout << a[i] << " ";
  cout << endl;
}
template <typename T>
void print(T **a, int row, int col) {
  for (int i = 0; i < row; ++i) {
    for (int j = 0; j < col; ++j)
      cout << a[i][j] << (j == col - 1 ? '\n' : ' ');
  }
}
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return f * x;
}
void write(int a) {
  if (a < 0) putchar('-'), a = -a;
  if (a >= 10) write(a / 10);
  putchar(a % 10 + 48);
}
void upt(const LL n, LL &tot) {
  tot = 0;
  for (LL i = 0; i < 18; ++i) {
    LL bit = (n / LL(pow(10LL, i))) % 10;
    tot += bit;
  }
}
void solve() {
  LL n, s;
  cin >> n >> s;
  LL res = 0, tot = 0;
  upt(n, tot);
  for (LL i = 0; i < 18; ++i) {
    if (tot <= s) break;
    LL bit = (n / LL(pow(10LL, i))) % 10;
    if (bit == 0) continue;
    LL dlt = (10LL - bit) * pow(10LL, i);
    res += dlt, n += dlt;
    upt(n, tot);
  }
  cout << res << endl;
}
int main() {
  int t = read();
  while (t--) solve();
  return 0;
}
