#include <bits/stdc++.h>
using namespace std;
long long q, n;
string a, b;
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> q;
  while (q--) {
    cin >> n >> a >> b;
    long long res = 0;
    for (long long i = 0; i < n; ++i) {
      for (long long j = 0; j <= i; ++j) {
        long long l = j;
        for (long long k = 0; k < n; ++k) {
          if (a[k] == b[l]) l++;
          if (l == i + 1) break;
        }
        if (l == i + 1) res = max(res, i - j + 1);
      }
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if (a != b) res = n + 1;
    cout << n - res << '\n';
  }
}
