#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string a, b;
    cin >> a >> b;
    int ca = 0, cb = 0;
    int k = b.length() - 1;
    while (1) {
      if (b[k] == '1') {
        break;
      }
      k--;
      cb++;
    }
    k = a.length() - 1;
    while (1) {
      if (ca >= cb && a[k] == '1') break;
      k--;
      ca++;
    }
    cout << ca - cb << endl;
  }
}
