#include <bits/stdc++.h>
const int inf = 1e9;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {-1, 0, 0, 1};
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, cas = 1;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y;
    if (x % y == 0)
      cout << "0" << endl;
    else if (x >= y) {
      long long z = x / y;
      long long n = y * (z + 1);
      cout << n - x << endl;
    } else
      cout << y - x << endl;
  }
}
