#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
  long long x = 0;
  bool neg = false;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') neg = true, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  if (neg) x = -x;
  return x;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
string first, second;
void input() { cin >> first >> second; }
void solve() {
  int n = first.length(), m = second.length();
  int px = 100, py = 100;
  for (int _x = m, i = 0; i < _x; ++i)
    if (second[i] == '1') py = m - i - 1;
  for (int _x = n - py, i = 0; i < _x; ++i)
    if (first[i] == '1') px = n - i - py - 1;
  cout << px << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    input();
    solve();
  }
  return 0;
}
