#include <bits/stdc++.h>
using namespace std;

int main() {
  int Q;
  cin >> Q;
  for (int q = 0; q < Q; q++) {
    string s, t;
    cin >> s >> t;
    int ls, lt;
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        ls = i;
        break;
      }
    }
    for (int i = t.size() - 1; i >= 0; i--) {
      if (t[i] == '1') {
        lt = i;
        break;
      }
    }
    int r = ls;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] != t[i]) {
        r = i;
        break;
      }
    }
    cout << abs(ls - r) + abs(lt - r) << endl;
  }
}

