#include <bits/stdc++.h>
using namespace std;
int t;
string a, b;
int main() {
  scanf("%d", &t);
  while (t--) {
    cin >> a >> b;
    int n = (int)a.size();
    int m = (int)b.size();
    int ans = 0;
    for (int i = n - 1, j = m - 1; i >= 0; --i) {
      if (b[j] == '1' && a[i] == '1') {
        ans = n - i - m + j;
        break;
      }
      if (b[j] == '0') j--;
    }
    printf("%d\n", ans);
  }
  return 0;
}
