#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, k, x, y, z, m, t, h, l, r, ans;
  cin >> t;
  while (t--) {
    cin >> x >> y;
    if (x < y) {
      cout << y - x << endl;
    } else {
      if (x % y == 0) {
        cout << 0 << endl;
      } else {
        cout << y * ((x / y) + 1) - x << endl;
      }
    }
  }
  return 0;
}
