#include <iostream>
#include <string>
#include <cstring>
using namespace std;
const int N = 20 + 5;
string words[N];
int g[N][N], vis[N];
void connection(const string &a,const string &b,int x,int y){
	int len = a.length();
	for(int i = 0; i < len-1; i++){ //不能有包含关系 
		bool ok = true;
		for(int j = 0; j < b.length() && j <= i; j++){
			if(a[len+j-i-1] != b[j]){
				ok = false;
				break;
			}
		}
		if(ok){
			if(i != b.length() -1) //不能有包含关系
			 	g[x][y] = i+1;
			return;
		}
	}
}
 
int ans = 0, n;
void solve(int u,int length){
	if(ans < length){
		ans = length;
	}
	for(int v = 0; v < n; v++){
		if(g[u][v] && vis[v] < 2){
			vis[v]++;
			solve(v,length+(int)words[v].length()-g[u][v]);
			vis[v]--;
		}
	}
}
 
int main(int argc, char** argv) {
	cin>> n; 
	char c;
	for(int i = 0; i < n; i++)
		cin>> words[i];
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			connection(words[i], words[j], i , j);
	cin>> c;
	string s;
	for(int i = 0; i < n; i++){
		if(words[i][0] == c){
			vis[i]++;
			solve(i,words[i].length());
			vis[i]--;
			}
	}	
	cout<< ans << endl;
	return 0;
}
/**************************************************************
	Problem: 1864
	User: admin
	Language: C++
	Result: Accepted
	Time:30 ms
	Memory:2080 kb
****************************************************************/