#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s, h;
    cin >> s >> h;
    if (s[s.length() - 1] == h[h.length() - 1]) {
      if (s[s.length() - 1] == 1) {
        cout << "0" << endl;
      } else {
        long long a = s.length() - 1;
        long long b = h.length() - 1;
        long long k = 0;
        while (h[b] == '0') {
          b--;
          k++;
        }
        a = a - k;
        long long d = 0;
        while (s[a] == '0') {
          d++;
          a--;
        }
        cout << d << endl;
      }
    } else {
      if (s[s.length() - 1] == '1') {
        long long p = h.length() - 1;
        long long y = 0;
        while (h[p] == '0') {
          p--;
          y++;
        }
        long long r = s.length() - y - 1;
        long long m = 0;
        while (s[r] == '0') {
          r--;
          m++;
        }
        cout << m << endl;
      } else {
        long long k = 0;
        long long p = s.length() - 1;
        while (s[p] == '0') {
          p--;
          k++;
        }
        cout << k << endl;
      }
    }
  }
  return 0;
}
