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