#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  int t;
  cin >> t;
  string a, b;
  while (t--) {
    cin >> a >> b;
    int flag, k = 0;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    for (int i = 0; i < a.length(); i++) {
      if (b[i] == '1') {
        flag = i;
        break;
      }
    }
    for (int i = flag; i < a.length(); i++) {
      if (a[i] == '0')
        k++;
      else
        break;
    }
    cout << k << endl;
  }
  return 0;
}
