#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    string x, y;
    cin >> x >> y;
    reverse(x.begin(), x.end());
    reverse(y.begin(), y.end());
    int a1, a2;
    int lenx = x.size();
    int leny = y.size();
    for (int i = 0; i < leny; ++i) {
      if (y[i] == '1') {
        a2 = i;
        break;
      }
    }
    int ans = 0;
    for (int i = 0; i < lenx; ++i) {
      if (x[i] == '1' && i >= a2) {
        ans = i - a2;
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
