#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline long long read() {
  char ch = ' ', last;
  long long ans = 0;
  while (ch < '0' || ch > '9') last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9') ans = ans * 10 + int(ch - '0'), ch = getchar();
  if (last == '-') return -ans;
  return ans;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
int T;
string x, y, a, b;
void init() {
  cin >> a >> b;
  x.clear(), y.clear();
  int k = 0, p = 0;
  for (int i = a.length(); i >= 1; i--) x += a[i - 1];
  for (int i = b.length(); i >= 1; i--) y += b[i - 1];
  for (int i = 0; i < y.length(); i++)
    if (y[i] == '1') {
      p = i;
      break;
    }
  for (int i = p; i < x.length(); i++)
    if (x[i] == '1') {
      k = i;
      break;
    }
  write(k - p), putchar('\n');
}
int main() {
  T = read();
  while (T--) init();
  return 0;
}
