#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int p = 0; p < t; p++) {
    string x, y;
    cin >> x >> y;
    int a = x.length();
    int b = y.length();
    int cnt = 0;
    for (int i = b - 1; i >= 0; i--) {
      if (y[i] == '0') {
        cnt++;
      } else {
        break;
      }
    }
    int ans = 0;
    for (int i = a - 1 - cnt; i >= 0; i--) {
      if (x[i] == '0') {
        ans++;
      } else {
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
