#include <bits/stdc++.h>
using namespace std;
int t, n, m;
string s, ss;
int lcs(string s, string ss, int m, int n) {
  int L[m + 1][n + 1];
  int i, j;
  for (i = 0; i <= m; i++) {
    for (j = 0; j <= n; j++) {
      if (i == 0 || j == 0)
        L[i][j] = 0;
      else if (s[i - 1] == ss[j - 1])
        L[i][j] = L[i - 1][j - 1] + 1;
      else
        L[i][j] = max(L[i - 1][j], L[i][j - 1]);
    }
  }
  return L[m][n];
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    cin >> s;
    cin >> ss;
    for (int i = 0; i < s.length() - 1; i++)
      while (s[i] == s[i + 1] && i < s.length() - 1) s.erase(i, 1);
    for (int i = 0; i < ss.length() - 1; i++)
      while (ss[i] == ss[i + 1] && i < ss.length() - 1) ss.erase(i, 1);
    cout << s.length() + ss.length() - lcs(s, ss, s.length(), ss.length())
         << '\n';
  }
}
