#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
void solve() {
  string s, t;
  int i, j;
  cin >> s >> t;
  reverse(s.begin(), s.end());
  reverse(t.begin(), t.end());
  for (i = 0; i < t.length(); i++) {
    if (t[i] == '1') {
      break;
    }
  }
  for (j = i; j < s.length(); j++) {
    if (s[j] == '1') {
      break;
    }
  }
  cout << j - i << "\n";
}
