#include <bits/stdc++.h>
using namespace std;
long long int cnt = 0;
void counter(long long int n) {
  while (n) {
    cnt++;
    n /= 10;
  }
}
int main() {
  long long int tc;
  cin >> tc;
  while (tc--) {
    string s;
    long long int k;
    cin >> s >> k;
    for (int j = 0; j < s.size(); j++) {
      counter((s[j] - '0') + k);
    }
    cout << cnt << endl;
  }
}
