#include <bits/stdc++.h>
using namespace std;
int tt = 0;
void solve() {
  string s, st;
  cin >> s >> st;
  int ans = 0, check = 0;
  for (int i = st.size() - 1; i >= 0; i--) {
    if (st[i] == '1') break;
    check++;
  }
  for (int i = s.size() - check - 1; i >= 0; i--) {
    if (s[i] == '1') break;
    ans++;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
