#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a, b;
  cin >> t;
  vector<int> res;
  for (int i = 0; i < t; i++) {
    cin >> a >> b;
    int count;
    if (a % b == 0) {
      count = 0;
    } else {
      count = b - (a % b);
    }
    res.push_back(count);
  }
  for (int i = 0; i < t; i++) cout << res[i] << endl;
  return 0;
}
