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