#include <bits/stdc++.h>
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9 + 7;
const int maxn = (int)2e5 + 5;
const int logn = 20;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string x, y;
    cin >> x >> y;
    while (y.size() < x.size()) y = "0" + y;
    int p = y.size() - 1;
    while (p > 0 && y[p] != '1') p--;
    int q = p;
    while (q > 0 && x[q] != '1') q--;
    cout << p - q << "\n";
  }
  return 0;
}
