#include <bits/stdc++.h>
using namespace std;
int firstOne(string s) {
  int len = s.length();
  for (int i = len - 1; i >= 0; i--) {
    if (s[i] == '1') {
      return len - i;
    }
  }
}
int firstOneAfter(string s, int idx) {
  int len = s.length();
  for (int i = len - idx; i >= 0; i--) {
    if (s[i] == '1') {
      return len - i;
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string x, y;
    cin >> x >> y;
    int firstOneX = firstOne(x), firstOneY = firstOne(y);
    if (firstOneX >= firstOneY) {
      cout << firstOneX - firstOneY << endl;
    } else {
      cout << firstOneAfter(x, firstOneY) - firstOneY << endl;
    }
  }
  return 0;
}
