#include <bits/stdc++.h>
using namespace std;
namespace INPUT {
const int L = 1 << 15;
char _buf[L], *S, *T, c;
char _gc() {
  if (S == T) {
    T = (S = _buf) + fread(_buf, 1, L, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
void readi(char *s, int &n) {
  for (c = _gc(); c < '0' || c > '1'; c = _gc())
    ;
  s[n = 1] = c;
  for (c = _gc(); c >= '0' && c <= '1'; s[++n] = c, c = _gc())
    ;
}
}  // namespace INPUT
using INPUT ::readi;
const int Maxn = 1E5 + 5;
int N, M;
char a[Maxn], b[Maxn];
void Work() {
  readi(a, N), readi(b, M);
  int t;
  for (t = M; b[t] == '0'; --t)
    ;
  t = M - t;
  for (int i = N - t; i >= 1; --i)
    if (a[i] == '1') {
      printf("%d\n", N - t - i);
      return;
    }
}
int main() {
  int test;
  cin >> test;
  while (test--) Work();
  return 0;
}
