#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
char str1[maxn], str2[maxn];
int len1, len2;
void change(char *str, int len) {
  char tmp;
  for (int i = 0, j = len - 1; i < j; i++, j--) {
    tmp = str[i];
    str[i] = str[j];
    str[j] = tmp;
  }
}
int main() {
  int T, res, ptr;
  scanf("%d", &T);
  while (T--) {
    scanf("%s", str1);
    scanf("%s", str2);
    len1 = strlen(str1);
    len2 = strlen(str2);
    change(str1, len1);
    change(str2, len2);
    res = 0;
    for (ptr = 0; str2[ptr] == '0'; ptr++)
      ;
    while (str1[ptr] == '0') {
      res++;
      ptr++;
    }
    printf("%d\n", res);
  }
  return 0;
}
