#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141592653589793238462643383279;
const long long MOD = 998244353;
const long long INF = 1e9;
const long double eps = 0.000000000000001;
void boot_up() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(15);
}
signed main() {
  boot_up();
  long long t;
  cin >> t;
  while (t--) {
    string x, y;
    cin >> x >> y;
    long long pos_x, pos_y;
    for (long long i = y.size() - 1; i >= 0; i--) {
      if (y[i] == '1') {
        pos_y = y.size() - i;
        break;
      }
    }
    for (long long i = x.size() - pos_y; i >= 0; i--) {
      if (x[i] == '1') {
        pos_x = x.size() - i;
        break;
      }
    }
    cout << pos_x - pos_y << endl;
  }
  return 0;
}
