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