#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t) {
    t--;
    long long a, b;
    cin >> a >> b;
    long long n = a / b + (bool)(a % b);
    cout << b * n - a << endl;
  }
  return 0;
}
