#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    long long int x;
    x = a % b;
    if (x == 0)
      cout << x << endl;
    else {
      long long int r = a / b;
      long long int res = (r + 1) * b - a;
      cout << res << endl;
    }
  }
}
