#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int nax = 1e6 + 10;
long long int i, j, k, x, n, m;
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    string x, y;
    cin >> x >> y;
    long long int n = x.length();
    long long int m = y.length();
    for (i = m - 1; i >= 0; i--) {
      if (y[i] == '1') break;
    }
    long long int p = m - (i);
    long long int ans = 0;
    for (j = n - p; j >= 0; j--) {
      if (x[j] != '1')
        ans++;
      else
        break;
    }
    cout << ans << endl;
  }
}
