#include <bits/stdc++.h>
using namespace std;
void print() { cout << "\n"; }
template <typename T, typename... Types>
void print(T arg, Types... args) {
  cout << arg << " ";
  print(args...);
}
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
int main() {
  long long n, tc, m;
  cin >> tc;
  while (tc--) {
    cin >> n >> m;
    cout << (m - (n % m)) % m << "\n";
  }
  return 0;
}
