#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, y;
  vector<long long> v;
  string s;
  set<long long> s1;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    long long a, b;
    cin >> a >> b;
    long long k = a / b;
    if (a % b == 0)
      cout << "0";
    else if (a > b) {
      k = k + 1;
      cout << (b * k) - a;
    } else if (a < b) {
      cout << b - a;
    }
    cout << endl;
  }
}
