#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test;
  cin >> test;
  while (test--) {
    cin >> s >> t;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    int l = 0, r = 0, ans = 0;
    while (1) {
      if ((s[l] == '1' && t[r] == '1') || l == (int)s.size() ||
          r == (int)t.size())
        break;
      if (s[l] == '0' && t[r] == '1') {
        l++;
        ans++;
      } else {
        l++;
        r++;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
