#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(long long int *array, int array_n, char middle = ' ') {
  for (int i = 0; i < array_n; i++)
    printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<long long int> &vec_s, int vec_n = -1,
                char middle = ' ') {
  if (vec_n == -1) vec_n = vec_s.size();
  for (int i = 0; i < vec_n; i++)
    printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void init() {}
int check(long long int a) {
  if (a == 0) return 0;
  return a % 10 + check(a / 10);
}
void solve() {
  int n, m;
  int i, j, k;
  long long int a, b, c, d;
  cin >> a >> b;
  c = a, d = 1;
  for (i = 0; i <= 18; i++, d *= 10) {
    c = ((c - 1) / d + 1) * d;
    if (check(c) <= b) break;
  }
  cout << c - a << endl;
}
int main() {
  int n, i;
  init();
  cin >> n;
  for (i = 0; i < n; i++) {
    solve();
  }
}
