#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long t;
  cin >> t;
  while (t--) {
    string x, y;
    long long pos1, pos2;
    cin >> x >> y;
    reverse(x.begin(), x.end());
    reverse(y.begin(), y.end());
    for (long long i = 0; i < y.length(); i++) {
      if (y[i] == '1') {
        pos1 = i;
        break;
      }
    }
    for (long long i = 0; i < x.length(); i++) {
      if (x[i] == '1' && pos1 <= i) {
        pos2 = i;
        break;
      }
    }
    long long ans = pos2 - pos1;
    cout << ans << endl;
  }
}
