#include <bits/stdc++.h>
using namespace std;
int T;
string a, b;
int len1, len2;
int main() {
  cin >> T;
  while (T--) {
    cin >> a >> b;
    len1 = a.size();
    len2 = b.size();
    int pos1, pos2;
    for (pos1 = 1; pos1 <= len2; pos1++)
      if (b[len2 - pos1] == '1') {
        break;
      }
    for (pos2 = pos1; pos2 <= len1; pos2++)
      if (a[len1 - pos2] == '1') {
        break;
      }
    cout << pos2 - pos1 << endl;
  }
  return 0;
}
