#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, i, a, c, ans, l;
  string s;
  cin >> t;
  while (t--) {
    cin >> a;
    cin >> s;
    c = 0;
    l = s.size();
    for (i = 0; i < l; i++) {
      if (s[i] == '9') c++;
    }
    if (c == l) {
      ans = a * c;
    } else {
      ans = (a * (l - 1));
    }
    cout << ans << endl;
  }
  return 0;
}
