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