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