#include <iostream>
#include <string>
#include <vector>
using namespace std;
string get_prefix(string s, int x) {
return s.substr(0, x);
}
string get_suffix(string s, int x) {
return s.substr(s.size() - x, x);
}
void sol() {
int n, k;
cin >> n >> k;
vector<string> v(k);
int ans = 0;
for (auto &e : v) cin >> e, ans += e.size();
for (int i = 0; i < v.size() - 1; i++) {
// 把 v[i] 和 v[i+1] 比較
for (int j = n; j >= 1; j--) {
if (get_suffix(v[i], j) == get_prefix(v[i+1], j)) {
// 更新目前找到的最大重疊前後綴
ans -= j;
break;
}
}
}
cout << ans << endl;
}
signed main() {
int t;
cin >> t;
while (t--) sol();
}