#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    string a, b;
    cin >> a >> b;
    int last = -1;
    for (int i = b.size() - 1; i >= 0; i--) {
      if (b[i] == '1') {
        last = i;
        break;
      }
    }
    a = a.substr(0, a.size() - (b.size() - 1 - last));
    int x = 0;
    for (int i = a.size() - 1; i >= 0; i--) {
      if (a[i] == '1') {
        x = i;
        break;
      }
    }
    cout << a.size() - 1 - x << endl;
  }
}
