#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    int l1 = a.length();
    int l2 = b.length();
    int posy = -1;
    for (int i = l2 - 1; i >= 0; i--) {
      if (b[i] == '1') {
        posy = l2 - 1 - i;
        break;
      }
    }
    int posx = 0;
    for (int i = l1 - 1 - posy; i >= 0; i--) {
      if (a[i] == '1') break;
      posx++;
    }
    cout << (posx) << '\n';
  }
  return 0;
}
