#include <bits/stdc++.h>
using namespace std;
int main() {
  long t;
  scanf("%ld", &t);
  while (t--) {
    string x, y;
    cin >> x >> y;
    reverse(x.begin(), x.end());
    reverse(y.begin(), y.end());
    long a, b, ans = 0, flag = 0;
    b = y.find('1');
    if (b == string::npos) {
      ans = 0;
    } else {
      for (long i = 0; i < x.size(); i++) {
        if (x[i] == '1') {
          if (i >= b) {
            ans = i - b;
            break;
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
