#include <bits/stdc++.h>
using namespace std;
int t;
void solve(string x, string y) {
  int ney = 0;
  int size_of_y = y.size() - 1;
  while (y[size_of_y] == '0') {
    size_of_y--;
    ney++;
  }
  int startinx = x.size() - ney - 1;
  int ans = 0;
  while (x[startinx] != '1') {
    startinx--;
    ans++;
  }
  cout << ans << '\n';
}
int main() {
  cin >> t;
  for (int i = 1; i <= t; i++) {
    string fx;
    string fy;
    cin >> fx >> fy;
    solve(fx, fy);
  }
}
