#include <bits/stdc++.h>
using namespace std;
int T;
char x[200010];
char y[200010];
int sx, sy;
char ans[200010];
int szAns;
char maxNum[200010];
int szMax;
int k;
bool add(int offset) {
  int px = 0;
  szAns = 0;
  while (px < offset) {
    ans[szAns] = x[px];
    px++;
    szAns++;
  }
  int c = 0;
  int py = 0;
  if (x[px] != '1' || y[py] != '1') return false;
  while ((px < sx) || (py < sy)) {
    ans[szAns] = c;
    if (px < sx) ans[szAns] = ans[szAns] + x[px] - '0';
    if (py < sy) ans[szAns] = ans[szAns] + y[py] - '0';
    c = ans[szAns] / 2;
    ans[szAns] = ans[szAns] % 2 + '0';
    szAns++;
    px++;
    py++;
  }
  while (c > 0) {
    ans[szAns] = c % 2 + '0';
    c = c / 2;
    szAns++;
  }
  ans[szAns] = '\0';
  return true;
}
int main() {
  scanf("%d\n", &T);
  for (int i = 0; i < T; i++) {
    scanf("%s\n", x);
    scanf("%s\n", y);
    k = -1;
    sx = strlen(x);
    sy = strlen(y);
    reverse(x, x + sx);
    reverse(y, y + sy);
    int pyOne = 0;
    while (y[pyOne] == '0') pyOne++;
    k = 0;
    while (x[pyOne + k] == '0') k++;
    printf("%d\n", k);
  }
  return 0;
}
