#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  size_t t;
  cin >> t;
  string x, y;
  int answer = 0;
  int last1X, last1Y;
  for (size_t i = 0; i < t; ++i) {
    cin >> x >> y;
    last1X = x.size();
    last1Y = y.size();
    last1X = find(x.rbegin(), x.rend(), '1') - x.rbegin();
    last1Y = find(y.rbegin(), y.rend(), '1') - y.rbegin();
    answer = 0;
    if (last1Y == y.size())
      answer = 0;
    else if (last1X == x.size()) {
      answer = max(0, int(x.size()) - int(y.size()));
    } else
      for (int i = x.size() - 1 - last1Y; i >= 0; i--) {
        if (x[i] == '1')
          break;
        else
          ++answer;
      }
    cout << answer << endl;
  }
  return 0;
}
