#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char s[maxn], t[maxn];
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%s%s", s + 1, t + 1);
    int lens = strlen(s + 1);
    int lent = strlen(t + 1);
    int tag = 0;
    for (int i = lent; i >= 1; i--) {
      if (t[i] == '1') {
        tag = lent - i + 1;
        break;
      }
    }
    int cnt = 0;
    for (int i = lens - tag + 1; i >= 1; i--) {
      if (s[i] == '1') break;
      cnt++;
    }
    printf("%d\n", cnt);
  }
  return 0;
}
