#include <bits/stdc++.h>
using namespace std;
void run() {
  string a, b;
  cin >> a >> b;
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  long long id = 0;
  for (long long i = 0; i < b.size(); i++) {
    if (b[i] == '1') {
      id = i;
      break;
    }
  }
  long long ans = 0;
  while (id + ans < a.size() && a[id + ans] != '1') ans++;
  cout << ans << '\n';
}
signed main() {
  long long t = 1;
  cin >> t;
  while (t--) run();
  return 0;
}
