#include <bits/stdc++.h>
using namespace std;
const int N = 2e4;
const int oo = 2e9;
string s, t;
int tt;
int main() {
  cin >> tt;
  while (tt--) {
    cin >> s;
    cin >> t;
    int i = t.size() - 1, cnt = 0, ans = -1;
    while (t[i] == '0') {
      ++cnt;
      --i;
      if (i < 0) break;
    }
    for (int i = s.size() - 1 - cnt; i >= 0; --i)
      if (s[i] == '1') {
        ans = i;
        break;
      }
    if (ans == -1) {
      cout << s.size() - t.size() << endl;
    } else {
      cout << s.size() - ans - cnt - 1 << endl;
    }
  }
}
