#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n, val;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (a % b == 0)
      cout << 0 << endl;
    else {
      val = b - (a % b);
      cout << val << endl;
    }
  }
  return 0;
}
