#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string s, d;
  while (t--) {
    cin >> s >> d;
    int i = 0, j = 0, k = 0;
    for (i = d.length() - 1; i >= 0; i--)
      if (d[i] == '1') break;
    i = d.length() - i;
    i = s.length() - i;
    while (s[i--] != '1') k++;
    cout << k << endl;
  }
  return 0;
}
