#include <bits/stdc++.h>
int main(int argc, char** argv) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int T;
  std::cin >> T;
  for (int q = 0; q < T; q++) {
    std::string y, x;
    std::cin >> x >> y;
    std::reverse(y.begin(), y.end());
    std::reverse(x.begin(), x.end());
    if (x[0] == y[0] && y[0] == '1')
      std::cout << 0 << std::endl;
    else {
      int yfo = 0;
      for (; yfo < y.length(); yfo++)
        if (y[yfo] == '1') break;
      int k = 0;
      for (int s = yfo; s < x.length(); s++)
        if (x[s] == '0')
          k++;
        else
          break;
      std::cout << k << std::endl;
    }
  }
  return 0;
}
