#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, k, j;
  string x, y;
  cin >> t;
  while (t--) {
    cin >> x;
    cin >> y;
    k = 0;
    for (i = (int)y.size() - 1; i >= 0; i--) {
      if (y[i] == '1') break;
    }
    for (j = (int)x.size() - 1 - ((int)y.size() - 1 - i); j >= 0; j--) {
      if (x[j] != '1')
        k++;
      else
        break;
    }
    cout << k << '\n';
  }
  return 0;
}
