#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  int T;
  cin >> T;
  while (T--) {
    string s, ss;
    cin >> s >> ss;
    reverse(s.begin(), s.end());
    reverse(ss.begin(), ss.end());
    int idx = 0;
    while (ss[idx] == '0') {
      idx++;
    }
    for (int i = idx;; i++) {
      if (s[i] == '1') {
        cout << i - idx << "\n";
        break;
      }
    }
  }
}
