#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
char x[maxn], y[maxn];
char tmp[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s %s", y, x);
    int len_y = strlen(y);
    int len_x = strlen(x);
    for (int i = 0; i < len_x; i++) {
      tmp[i] = x[len_x - i - 1];
    }
    for (int i = 0; i < len_x; i++) {
      x[i] = tmp[i];
    }
    for (int i = 0; i < len_y; i++) {
      tmp[i] = y[len_y - i - 1];
    }
    for (int i = 0; i < len_y; i++) {
      y[i] = tmp[i];
    }
    int pos = 0;
    for (int i = 0; i < len_x; i++) {
      if (x[i] == '1') {
        pos = i;
        break;
      }
    }
    int k = 0;
    for (int i = pos; i < len_y; i++) {
      if (y[i] == '1') {
        break;
      }
      k++;
    }
    printf("%d\n", k);
  }
  return 0;
}
