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