#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    string x, y;
    cin >> x >> y;
    int lx = x.size(), ly = y.size();
    int py = 1;
    while (y[ly - py] == '0') ++py;
    int px = py;
    while (lx >= px && x[lx - px] == '0') ++px;
    cout << px - py << endl;
  }
  return 0;
}
