#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i;
  cin >> t;
  for (i = 0; i < t; i++) {
    int k = 0, l;
    string a, b;
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    while (b[k] != '1') k++;
    for (l = 0; l < a.size(); l++) {
      if (a[l] == '1' && l >= k) break;
    }
    cout << l - k << endl;
  }
}
