#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long n, long long d) {
  long long res = 1;
  while (n) {
    if (n & 1 != 0) {
      res = ((res % d) * ((a % d + d) % d)) % d;
      n--;
    } else {
      a = ((((a % d + d) % d)) * (((a % d + d) % d))) % d;
      n >>= 1;
    }
  }
  return res;
}
void SieveOfEratosthenes(long long N, vector<long long>& s) {
  s[0] = 0;
  s[1] = 0;
  s[2] = 1;
  s[3] = 1;
  bool prime[N + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= N; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= N; i += p) {
        prime[i] = false;
        s[i] = 0;
      }
    }
  }
}
struct not_digit {
  bool operator()(const char c) { return c != ' ' && !std::isdigit(c); }
};
void extractNum(string str, vector<long long>& numbers) {
  not_digit not_a_digit;
  string::iterator end = std::remove_if(str.begin(), str.end(), not_a_digit);
  string all_numbers(str.begin(), end);
  stringstream ss(all_numbers);
  for (long long i = 0; ss >> i;) {
    numbers.push_back(i);
  }
}
void getWords(string str, vector<string>& vec, unordered_set<string>& Set) {
  string word;
  stringstream iss(str);
  while (iss >> word) {
    Set.insert(word);
    vec.push_back(word);
  }
}
bool isPower(long long n) {
  if (n <= 1) return true;
  for (long long x = 2; x <= sqrt(n); x++) {
    unsigned p = x;
    while (p <= n) {
      p *= x;
      if (p == n) return true;
    }
  }
  return false;
}
string decimalToBinary(long long n) {
  string s = bitset<64>(n).to_string();
  const auto loc1 = s.find('1');
  if (loc1 != string::npos) return s.substr(loc1);
  return "0";
}
double slope(long long x1, long long y1, long long x2, long long y2) {
  double angle;
  angle = (y2 - y1) / (double)(x2 - x1);
  return angle;
}
bool isPrime(long long n) {
  if (n == 1)
    return false;
  else {
    for (long long i = 2; i * i <= n; i++) {
      if (n % i == 0) return false;
    }
    return true;
  }
}
long long Power(long long a, long long n) {
  long long res = 1;
  if (n == 0) return 1;
  while (n) {
    if (n & 1 != 0) {
      res *= a;
      n--;
    } else {
      a *= a;
      n >>= 1;
    }
  }
  return res;
}
long long Mod(long long x) {
  return ((x % 1000000007 + 1000000007) % 1000000007);
}
long long add(long long a, long long b) { return Mod(Mod(a) + Mod(b)); }
long long mul(long long a, long long b) { return Mod(Mod(a) * Mod(b)); }
const long long N = 2e5 + 2;
long long fact[N];
void precalc() {
  fact[0] = 1;
  for (long long i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
  }
}
long long inv(long long x) { return pow(x, 1000000007 - 2); }
long long divide(long long a, long long b) { return mul(a, inv(b)); }
long long nCr(long long n, long long r) {
  return divide(fact[n], mul(fact[r], fact[n - r]));
}
long long solve() {
  long long a, b;
  cin >> a >> b;
  long long diff = b - a;
  long long res = 0, one = 1;
  string s;
  for (long long i = 0; i < log2(b) + 1; i++) {
    if (diff > (one << i))
      continue;
    else if (a & (one << i) && b & (one << i))
      res += (one << i);
  }
  return res;
}
long long cost(long long L, long long R, char ch, string& s) {
  long long cnt = 0;
  for (long long i = L; i <= R; i++)
    if (s[i] != ch) cnt++;
  return cnt;
}
long long getMin(long long l, long long r, char ch, string& s) {
  if (l == r) {
    if (s[l] == ch)
      return 0;
    else
      return 1;
  }
  long long mid = (l + r) >> 1;
  return min(cost(l, mid, ch, s) + getMin(mid + 1, r, ch + 1, s),
             cost(mid + 1, r, ch, s) + getMin(l, mid, ch + 1, s));
}
long long getMax(long long base, long long ele) {
  long long i, num = 1, temp = 0;
  while (num < ele) {
    num *= base;
    temp++;
  }
  return temp;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x;
  cin >> x;
  while (x--) {
    long long n, i, value, k, flag = 1, sumxor = 0, sum = 0;
    string s, p;
    cin >> s >> p;
    long long sSize = s.size(), pSize = p.size(), index = 0;
    for (i = pSize - 1; i >= 0; i--) {
      if (p[i] == '1') {
        index = i;
        break;
      }
    }
    long long f = sSize - 1 - (pSize - 1 - i), ans = 0;
    for (i = f; i >= 0; i--) {
      if (s[i] == '1') break;
      ans++;
    }
    cout << ans << "\n";
  }
}
