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