#include <bits/stdc++.h>
using namespace std;
string a, b;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    int id, cnt = 0;
    for (id = 0; id < b.size(); id++)
      if (b[id] == '1') break;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == '1') {
        if (i >= id) {
          cout << i - id << endl;
          break;
        }
      }
    }
  }
  return 0;
}
