#include <bits/stdc++.h>
using namespace std;
char st1[100010], st2[100010];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%s", st1 + 1);
    n = strlen(st1 + 1);
    scanf("%s", st2 + 1);
    m = strlen(st2 + 1);
    int pos = 0, ans = 0;
    while (st2[m - pos] != '1') pos++;
    while (st1[n - pos] != '1') pos++, ans++;
    printf("%d\n", ans);
  }
  return 0;
}
