#include <bits/stdc++.h>
using namespace std;
string sum(string a, string b) {
  string result = "";
  int s = 0;
  int i = a.size() - 1, j = b.size() - 1;
  while (i >= 0 || j >= 0 || s == 1) {
    s += ((i >= 0) ? a[i] - '0' : 0);
    s += ((j >= 0) ? b[j] - '0' : 0);
    result = char(s % 2 + '0') + result;
    s /= 2;
    i--;
    j--;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    int i, j, k = 0;
    int n = s1.size(), m = s2.size();
    for (i = m - 1; i >= 0; i--)
      if (s2[i] == '1') break;
    int d = n - m + i;
    if (i == -1 || s1[d] == s2[i]) {
      cout << 0 << endl;
      continue;
    }
    for (j = d - 1; j >= 0; j--) {
      if (s1[j] == '1') break;
      k++;
    }
    cout << k + 1 << endl;
  }
}
