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