#include <bits/stdc++.h>
using namespace std;
int T;
string a, b;
int main() {
  cin >> T;
  while (T--) {
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    int i = 0, j = 0;
    for (; j < b.size(); ++j)
      if (b[j] == '1') break;
    if (j == b.size()) {
      cout << 0 << endl;
      return 0;
    }
    for (; i < a.size(); ++i)
      if (a[i] == '1' && i >= j) break;
    cout << i - j << endl;
  }
  return 0;
}
