#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
int main() {
  string x, y;
  int t, c = 0;
  cin >> t;
  while (t--) {
    c = 0;
    cin >> x >> y;
    reverse(x.begin(), x.end());
    reverse(y.begin(), y.end());
    int f2 = y.find('1');
    if (f2 < x.size()) {
      while (x[f2] != '1') f2++, c++;
    }
    cout << c << endl;
  }
  return 0;
}
