#include <bits/stdc++.h>
using namespace std;
int cases, no1, no2;
int main() {
  cin >> cases;
  for (size_t i = 0; i < cases; i++) {
    cin >> no1 >> no2;
    if (no1 % no2 == 0) {
      cout << 0 << endl;
    } else {
      cout << no2 - (no1 % no2) << endl;
    }
  }
}
