#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s, p;
    cin >> s >> p;
    reverse(s.begin(), s.end());
    reverse(p.begin(), p.end());
    vector<int> v;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        v.push_back(i);
      }
    }
    int x = -1;
    for (int i = 0; i < p.length(); i++) {
      if (p[i] == '1') {
        x = i;
        break;
      }
    }
    long long ans = 0;
    if (x != -1) {
      for (int i = 0; i < v.size(); i++) {
        if (v[i] >= x) {
          ans = abs(v[i] - x);
          break;
        }
      }
    }
    cout << ans << endl;
  }
}
