#include <bits/stdc++.h>
using namespace std;
const int maxn = (1e5 + 5);
int n, m, k, l, s, t, r;
int a[maxn];
int main() {
  int T;
  cin >> T;
  while (T--) {
    string a, b;
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    int id_x = 0;
    for (int i = 0; i < b.length(); i++)
      if (b[i] == '1') {
        id_x = i;
        break;
      }
    int ans = 0;
    for (int i = id_x; i < a.length(); i++)
      if (a[i] == '1') {
        break;
      } else
        ans++;
    cout << ans << endl;
  }
  return 0;
}
