#include <bits/stdc++.h>
using namespace std;
using namespace std;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    while (b.back() == '0') {
      b.pop_back();
      a.pop_back();
    }
    long long k = 0;
    long long n = a.size();
    while (a[n - k - 1] == '0') k++;
    cout << k << endl;
  }
  return 0;
}
