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 <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int maxn = 14;
const int maxl = 21;

int dp[1<<maxn][maxn][maxl];
int next_str[maxn][maxl][maxn];
int next_len[maxn][maxl][maxn];
int cost[maxn][maxl][maxn];

string needed_str(const string &s1, const string &s2){
  for(int i = min(s1.size(), s2.size()); i > 0; i--){
    if(s1.substr(s1.size()-i, i) == s2.substr(0, i)) return s2.substr(i);
  }
  return s2;
}

void set_next(int &strID, int &len, const string &str, const vector<string> &vs){
  int best = 0;
  REP(i, vs.size()) {
    for(int j = min(str.size(), vs[i].size()); j > 0; j--){
      if(str.substr(str.size() - j, j) == vs[i].substr(0, j) && best < j){
	strID = i;
	len = best = j;
      }
    }
  }
}

void init_table(const vector<string> &vs){
  REP(i, vs.size())REP(j, vs[i].size() + 1){
    string s1 = vs[i].substr(0, j);
    REP(k, vs.size()){
      string s2 = needed_str(s1, vs[k]);
      cost[i][j][k] = s2.size();
      set_next(next_str[i][j][k], next_len[i][j][k], s1 + s2, vs);
    }
  }
}

vector<string> erase_substr(vector<string> vs){
  int n = vs.size();
  REP(i, n)REP(j,n)if(i != j){
    if(vs[i] == vs[j]){
      if(i < j) vs[j] = "";
    }else if(vs[i].find(vs[j]) != string::npos){
      vs[j] = "";
    }
  }
  vector<string> res;
  REP(i, n)if(vs[i] != "") res.PB(vs[i]);
  return res;
}

int main(){
  int N;
  
  while(cin >> N && N){
    vector<string> vs;
    REP(i, N){
      string s;
      cin >> s;
      vs.PB(s);
    }
    
    vs = erase_substr(vs);
    init_table(vs);
    
    
    N = vs.size();
    fill(&dp[0][0][0], &dp[0][0][0] + (1 << maxn) * maxn * maxl, INF);
    dp[0][0][0] = 0;
    
    REP(mask, 1 << N)REP(i, N)REP(j, vs[i].size() + 1){
      if(dp[mask][i][j] == INF) continue;
      REP(k, N){
        int nstr = dp[mask][i][j] + cost[i][j][k];
        int &str = dp[mask | (1 << k)][next_str[i][j][k]][next_len[i][j][k]];
	if(str > nstr) str = nstr;
      }
    }
    
    int res = INF;
    REP(i, N)REP(j, vs[i].size() + 1){
      int s = dp[(1 << N) - 1][i][j];
      if(s != -1) res = min(res, s);
    }
    cout << res << endl;
  }
  return 0;
}