Problem: Recent improvements in information and communication technology have made it possible to provide municipal service to a wider area more quickly and with less costs. Stimulated by this, and probably for saving their not sufficient funds, mayors of many cities started to discuss on mergers of their cities.

There are, of course, many obstacles to actually put the planned mergers in practice. Each city has its own culture of which citizens are proud. One of the largest sources of friction is with the name of the new city. All citizens would insist that the name of the new city should have the original name of their own city at least as a part of it. Simply concatenating all the original names would, however, make the name too long for everyday use.

You are asked by a group of mayors to write a program that finds the shortest possible name for the new city that includes all the original names of the merged cities. If two or more cities have common parts, they can be overlapped. For example, if "FUKUOKA", "OKAYAMA", and "YAMAGUCHI" cities are to be merged, "FUKUOKAYAMAGUCHI" is such a name that include all three of the original city names. Although this includes all the characters of the city name "FUKUYAMA" in this order, it does not appear as a consecutive substring, and thus "FUKUYAMA" is not considered to be included in the name.



Input

The input is a sequence of datasets. Each dataset begins with a line containing a positive integer n (n ≤ 14), which denotes the number of cities to be merged. The following n lines contain the names of the cities in uppercase alphabetical letters, one in each line. You may assume that none of the original city names has more than 20 characters. Of course, no two cities have the same name.

The end of the input is indicated by a line consisting of a zero.

Output

For each dataset, output the length of the shortest possible name of the new city in one line. The output should not contain any other characters.

Examples

Input

3


Output

16


Input

3
FUKUOKA
OKAYAMA
YAMAGUCHI
3
FUKUOKA
FUKUYAMA
OKAYAMA
2
ABCDE
EDCBA
4
GA
DEFG
CDDE
ABCD
2
ABCDE
C
14
AAAAA
BBBBB
CCCCC
DDDDD
EEEEE
FFFFF
GGGGG
HHHHH
IIIII
JJJJJ
KKKKK
LLLLL
MMMMM
NNNNN
0


Output

16
19
9
9
5
70

Solution (in CPP):

Solution:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 16;
const int INF = 100000;
string S[MAXN];
int dp[MAXN][1<<MAXN];
int memo[MAXN][MAXN][22];
int N;

int dfs(int now, int state) {
    int& ret = dp[now][state];
    if (ret >= 0) return ret;
    if (state == (1<<N)-1) return ret = 0;
    ret = INF;
    int sz = S[now].size();
    for (int i = 0; i < N; i++) if (((state>>i)&1) == 0) {
        int isz = S[i].size();
        for (int j = max(0, sz+1-isz); j <= sz; j++) {
            int ok = memo[now][i][j];
            if (ok) {
                int nstate = state|ok;
                ret = min<int>(ret, (isz-(sz-j)) + dfs(i, nstate));
            }
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (cin >> N) {
        if (N==0) break;
        for (int i = 0; i < N; i++)
            cin >> S[i];
        int ans = INF;
        memset(dp, -1, sizeof(dp));
        memset(memo, 0, sizeof(memo));
        for (int n = 0; n < N; n++) {
            int sz = S[n].size();
            for (int i = 0; i < N; i++) {
                int isz = S[i].size();
                for (int j = max(0, sz+1-isz); j <= sz; j++) {
                    const string s = S[n].substr(j);
                    const string t = S[i].substr(0, s.size());
                    if (s == t) {
                        const string u = s+S[i].substr(t.size());
                        int& ok = memo[n][i][j];
                        for (int k = 0; k < N; k++) {
                            if (u.find(S[k]) != string::npos) ok |= 1<<k;
                        }
                    }
                }
            }
        }
        for (int i = 0; i < N; i++) {
            int state = 0;
            const string u = S[i];
            for (int j = 0; j < N; j++) {
                if (u.find(S[j]) != string::npos) state |= 1<<j;
            }
            ans = min<int>(ans, S[i].size() + dfs(i, state));
        }
        cout << ans << endl;
    }
    return 0;
}