#include <bits/stdc++.h>
using namespace std;
char a[100010];
char b[100010];
int main() {
  int t;
  cin >> t;
  while (t--) {
    scanf("%s", a);
    scanf("%s", b);
    int lena = strlen(a);
    int lenb = strlen(b);
    int cnt = 0;
    for (int i = lenb - 1; i >= 0; i--) {
      if (b[i] == '1') break;
      cnt++;
    }
    int ans = 0;
    for (int i = lena - 1 - cnt; i >= 0; i--) {
      if (a[i] == '1') break;
      ans++;
    }
    printf("%d\n", ans);
  }
}
