#include <bits/stdc++.h>
using namespace std;
char a[(100000 + 10)], b[(100000 + 10)];
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%s%s", a, b);
    int n = strlen(a), m = strlen(b);
    int x = 0;
    for (int i = m - 1; i >= 0; i--) {
      if (b[i] == '0')
        x++;
      else
        break;
    }
    int y = 0;
    for (int i = n - 1 - x; i >= 0; i--) {
      if (a[i] == '0') continue;
      y = i;
      break;
    }
    printf("%d\n", n - y - x - 1);
  }
  return 0;
}
