#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int maxn = 300030;
char x[maxn], y[maxn];
int T;
int main(int argc, char const *argv[]) {
  scanf("%d", &T);
  while (T--) {
    scanf("%s", x);
    scanf("%s", y);
    int l1 = strlen(x);
    int l2 = strlen(y);
    int cnt = 0;
    for (int i = l2 - 1; i >= 0; --i) {
      if (y[i] == '0')
        cnt++;
      else
        break;
    }
    int ans = 0;
    for (int i = l1 - cnt - 1; i >= 0; --i) {
      if (x[i] == '0')
        ans++;
      else
        break;
    }
    printf("%d\n", ans);
  }
  return 0;
}
