#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char s1[maxn], s2[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s%s", s1, s2);
    int len1 = strlen(s1);
    int len2 = strlen(s2);
    int pos1 = 0;
    for (int i = 0; i < len2; i++) {
      if (s2[i] == '1') pos1 = i;
    }
    int pos0 = 0;
    for (int i = 0; i <= len1 - len2 + pos1; i++) {
      if (s1[i] == '1') pos0 = i;
    }
    printf("%d\n", len1 - pos0 - len2 + pos1);
  }
}
