#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    double a, b;
    cin >> a >> b;
    cout.setf(ios::fixed);
    if (double(a / b) > (long long int)(a / b))
      cout << setprecision(0)
           << ((long long int)(a / b) + 1) * b - (long long int)a << endl;
    else
      cout << 0 << endl;
  }
}
