#include <bits/stdc++.h>
using namespace std;
string s1;
string s2;
void solve() {
  cin >> s1 >> s2;
  reverse((s1).begin(), (s1).end());
  reverse((s2).begin(), (s2).end());
  int a = -1;
  for (int i = 0, _n = ((int)((s2).size())); i < _n; ++i) {
    if (s2[i] == '1') {
      a = i;
      break;
    }
  }
  if (a == -1) throw 1;
  int b = -1;
  for (int i = a; i < (int)((s1).size()); i++) {
    if (s1[i] == '1') {
      b = i;
      break;
    }
  }
  if (b == -1) throw 1;
  cout << (b - a) << endl;
}
void solution() {
  int t;
  cin >> t;
  for (int i = 0, _n = (t); i < _n; ++i) {
    solve();
  }
}
int main() {
  solution();
  return 0;
}
