#include <bits/stdc++.h>
using namespace std;
string sa, sb;
int T;
int main() {
  cin >> T;
  while (T--) {
    cin >> sa >> sb;
    size_t pb = sb.find_last_of('1');
    size_t pa = sa.find_last_of('1', sa.size() - (sb.size() - pb));
    cout << (sa.size() - pa) - (sb.size() - pb) << endl;
  }
}
