#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x = 0;
  cin >> t;
  while (t--) {
    string s, a;
    int c1[130] = {0}, c2[130] = {0};
    cin >> s >> a;
    for (int i = 0; i < s.size(); i++) {
      c1[s[i]]++;
    }
    for (int i = 0; i < a.size(); i++) {
      c2[a[i]]++;
    }
    for (int i = 0; i < 130; i++) {
      int minn = min(c1[i], c2[i]);
      x += minn;
    }
    cout << x << endl;
  }
  return 0;
}
