#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int T;
  cin >> T;
  while (T--) {
    string x, y;
    cin >> x >> y;
    int n_y = y.length() - 1;
    while (0 < n_y && y[n_y] != '1') n_y--;
    int n_x = x.length() - (y.length() - n_y);
    while (0 < n_x && x[n_x] != '1') n_x--;
    cout << (x.length() - n_x) - (y.length() - n_y) << endl;
    ;
  }
  return 0;
}
