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