#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a;
    cin >> b;
    int len1 = a.length();
    int len2 = b.length();
    int i, j, k, index = 0;
    for (i = len2 - 1; i >= 0; i--) {
      if (b[i] == '1') {
        break;
      }
      index++;
    }
    int count = 0;
    for (i = len1 - index - 1; i >= 0; i--) {
      if (a[i] == '1') {
        break;
      }
      count++;
    }
    cout << count << endl;
  }
  return 0;
}
