#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m;
char s[100005], t[100005];
void work() {
  scanf("%s%s", s + 1, t + 1);
  n = strlen(s + 1), m = strlen(t + 1);
  int x = 0;
  for (register int i = (m); i >= (1); --i)
    if (t[i] == '1') {
      x = i;
      break;
    }
  int y = n - m + x;
  for (register int i = (y); i >= (1); --i)
    if (s[i] == '1') {
      cout << x - i + n - m << endl;
      return;
    }
}
int main() {
  int T = read();
  while (T--) work();
  return 0;
}
