#include <bits/stdc++.h>
using namespace std;
void onlinejudge() {}
int main() {
  onlinejudge();
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    if (n % m == 0)
      cout << 0 << endl;
    else
      cout << m - n % m << endl;
  }
  return 0;
}
