#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
#define loop(i,n) for(int i = 0,_ = (n);i < _;i++)
#define lp(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.begin(),v.end()
#define omani dance();
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sz(v) (int)v.size()
#define uq(c) (c).resize(unique(all(c)) - (c).begin())
typedef long long ll;
#define clr(v,val) memset(v,val,sizeof v)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
void dance()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

bool comp(pair<int, int>x, pair<int, int>y)
{
	if (x.first == y.first) return x.second<y.second;
	return x.first>y.first;
}
void PLAY() {

	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);

	cout << fixed << setprecision(15);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
string s; ll n;

double eq(int x1, int y1, int x2, int y2)
{
	double dis;
	dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	dis = sqrt(dis);
	return dis;
}
bool up(string s)
{
	for (int i = 0; i < s.size(); i++)
	{
		if (isupper(s[i]))return 1;
	}
	return 0;
}
vector <int> node[200000 + 9];
bool qq[250];
int main()
{
	omani

		int n, m;double  x;
	vector<vector<int>>vv(250);
	cin >> n >> m >> x; bool f = 0; int c = 0;
	map<string, pair<int, int>>mp; string str = ""; string s;
	char ch;
	for (int i = 1; i <=n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> ch;

			if (ch == 'S')
			{
				f = 1;

				str += "S";
				mp[str]=make_pair(i, j);
			}
			else
			{
				vv[int(ch)].push_back(i), vv[int(ch)].push_back(j);
				qq[ch] = 1;
			}
		}

	}

	int llll; cin >> llll;
	int ans = 0;
	cin >> s;
	map<char, int>mm;
	for (int i = 0; i < s.size(); i++)
		mm[s[i]]++;

	if (up(s) && !f&&s[0]!='S')
		return cout << -1, 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (qq[int(tolower(int(s[i])))] == 0&&s[i]!='S')
			return cout << -1, 0;
	}
	bool as = 0;
	sort(all(s));
	uq(s);
	for (int i = 0; i < s.size(); i++)
	{
		double mn = 9999999.9; double mnn = 9999999.9;
		if (isupper(s[i]) &&f)
		{
			as = 1;

			for (int j = 0; j < vv[int(tolower(int(s[i])))].size(); j += 2)
			{

				string r = str;
				for (int k = 0; k < str.size(); k++)
				{
					double dd = eq(mp[r].first, mp[r].second, vv[int(tolower(int(s[i])))][j], vv[int(tolower(int(s[i])))][j + 1]);
					if (dd < mn)
						mn = dd;
					r.pop_back();
				}
				if (mnn > mn)
				{
					mnn = mn;
				}

			}

			if (mnn > x&&mnn!= 9999999.9)
			{
				as = 0;
				ans+=mm[toupper(s[i])];
			}
		}

	}
	//if (as)
		cout << ans;

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
#define loop(i,n) for(int i = 0,_ = (n);i < _;i++)
#define lp(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.begin(),v.end()
#define omani dance();
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sz(v) (int)v.size()
#define uq(c) (c).resize(unique(all(c)) - (c).begin())
typedef long long ll;
#define clr(v,val) memset(v,val,sizeof v)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
void dance()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

bool comp(pair<int, int>x, pair<int, int>y)
{
	if (x.first == y.first) return x.second<y.second;
	return x.first>y.first;
}
void PLAY() {

	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);

	cout << fixed << setprecision(15);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
string s; ll n;

double eq(int x1, int y1, int x2, int y2)
{
	double dis;
	dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	dis = sqrt(dis);
	return dis;
}
bool up(string s)
{
	for (int i = 0; i < s.size(); i++)
	{
		if (isupper(s[i]))return 1;
	}
	return 0;
}
vector <int> node[200000 + 9];
bool qq[250];
int main()
{
	omani

		int n, m;double  x;
	vector<vector<int>>vv(250);
	cin >> n >> m >> x; bool f = 0; int c = 0;
	map<string, pair<int, int>>mp; string str = ""; string s;
	char ch;
	for (int i = 1; i <=n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> ch;

			if (ch == 'S')
			{
				f = 1;

				str += "S";
				mp[str]=make_pair(i, j);
			}
			else
			{
				vv[int(ch)].push_back(i), vv[int(ch)].push_back(j);
				qq[ch] = 1;
			}
		}

	}

	int llll; cin >> llll;
	int ans = 0;
	cin >> s;
	map<char, int>mm;
	for (int i = 0; i < s.size(); i++)
		mm[s[i]]++;

	if (up(s) && !f||(s[0]=='S'&& s.size()==1))
		return cout << -1, 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (qq[int(tolower(int(s[i])))] == 0&&s[i]!='S')
			return cout << -1, 0;
	}
	bool as = 0;
	sort(all(s));
	uq(s);
	for (int i = 0; i < s.size(); i++)
	{
		double mn = 9999999.9; double mnn = 9999999.9;
		if (isupper(s[i]) &&f)
		{
			as = 1;

			for (int j = 0; j < vv[int(tolower(int(s[i])))].size(); j += 2)
			{

				string r = str;
				for (int k = 0; k < str.size(); k++)
				{
					double dd = eq(mp[r].first, mp[r].second, vv[int(tolower(int(s[i])))][j], vv[int(tolower(int(s[i])))][j + 1]);
					if (dd < mn)
						mn = dd;
					r.pop_back();
				}
				if (mnn > mn)
				{
					mnn = mn;
				}

			}

			if (mnn > x&&mnn!= 9999999.9)
			{
				as = 0;
				ans+=mm[toupper(s[i])];
			}
		}

	}
	//if (as)
		cout << ans;

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
#define loop(i,n) for(int i = 0,_ = (n);i < _;i++)
#define lp(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.begin(),v.end()
#define omani dance();
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sz(v) (int)v.size()
#define uq(c) (c).resize(unique(all(c)) - (c).begin())
typedef long long ll;
#define clr(v,val) memset(v,val,sizeof v)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
void dance()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

bool comp(pair<int, int>x, pair<int, int>y)
{
	if (x.first == y.first) return x.second<y.second;
	return x.first>y.first;
}
void PLAY() {

	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);

	cout << fixed << setprecision(15);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
string s; ll n;

double eq(int x1, int y1, int x2, int y2)
{
	double dis;
	dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	dis = sqrt(dis);
	return dis;
}
bool up(string s)
{
	for (int i = 0; i < s.size(); i++)
	{
		if (isupper(s[i]))return 1;
	}
	return 0;
}
vector <int> node[200000 + 9];
bool qq[250];
int main()
{
	omani

		int n, m;double  x;
	vector<vector<int>>vv(250);
	cin >> n >> m >> x; bool f = 0; int c = 0;
	map<string, pair<int, int>>mp; string str = ""; string s;
	char ch;
	for (int i = 1; i <=n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> ch;

			if (ch == 'S')
			{
				f = 1;

				str += "S";
				mp[str]=make_pair(i, j);
			}
			else
			{
				vv[int(ch)].push_back(i), vv[int(ch)].push_back(j);
				qq[ch] = 1;
			}
		}

	}

	int llll; cin >> llll;
	int ans = 0;
	cin >> s;
	map<char, int>mm;
	for (int i = 0; i < s.size(); i++)
		mm[s[i]]++;

	if (up(s) && !f)
		return cout << -1, 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (qq[int(tolower(int(s[i])))] == 0&&s[i]!='S')
			return cout << -1, 0;
	}
	bool as = 0;
	sort(all(s));
	uq(s);
	for (int i = 0; i < s.size(); i++)
	{
		double mn = 9999999.9; double mnn = 9999999.9;
		if (isupper(s[i]) &&f)
		{
			as = 1;

			for (int j = 0; j < vv[int(tolower(int(s[i])))].size(); j += 2)
			{

				string r = str;
				for (int k = 0; k < str.size(); k++)
				{
					double dd = eq(mp[r].first, mp[r].second, vv[int(tolower(int(s[i])))][j], vv[int(tolower(int(s[i])))][j + 1]);
					if (dd < mn)
						mn = dd;
					r.pop_back();
				}
				if (mnn > mn)
				{
					mnn = mn;
				}

			}

			if (mnn > x&&mnn!= 9999999.9)
			{
				as = 0;
				ans+=mm[toupper(s[i])];
			}
		}

	}
	//if (as)
		cout << ans;

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
#define loop(i,n) for(int i = 0,_ = (n);i < _;i++)
#define lp(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.begin(),v.end()
#define omani dance();
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sz(v) (int)v.size()
#define uq(c) (c).resize(unique(all(c)) - (c).begin())
typedef long long ll;
#define clr(v,val) memset(v,val,sizeof v)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
void dance()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

bool comp(pair<int, int>x, pair<int, int>y)
{
	if (x.first == y.first) return x.second<y.second;
	return x.first>y.first;
}
void PLAY() {

	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);

	cout << fixed << setprecision(15);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
string s; ll n;

double eq(int x1, int y1, int x2, int y2)
{
	double dis;
	dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	dis = sqrt(dis);
	return dis;
}
bool up(string s)
{
	for (int i = 0; i < s.size(); i++)
	{
		if (isupper(s[i]))return 1;
	}
	return 0;
}
vector <int> node[200000 + 9];
bool qq[250];
int main()
{
	omani

		int n, m;double  x;
	vector<vector<int>>vv(250);
	cin >> n >> m >> x; bool f = 0; int c = 0;
	map<string, pair<int, int>>mp; string str = ""; string s;
	char ch;
	for (int i = 1; i <=n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> ch;

			if (ch == 'S')
			{
				f = 1;

				str += "S";
				mp[str]=make_pair(i, j);
			}
			else
			{
				vv[int(ch)].push_back(i), vv[int(ch)].push_back(j);
				qq[ch] = 1;
			}
		}

	}

	int llll; cin >> llll;
	int ans = 0;
	cin >> s;
	if (up(s) && !f)
		return cout << -1, 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (qq[int(tolower(int(s[i])))] == 0&&s[i]!='S')
			return cout << -1, 0;
	}
	bool as = 0;

	for (int i = 0; i < s.size(); i++)
	{
		double mn = 9999999.9; double mnn = 9999999.9;
		if (isupper(s[i]) &&f)
		{
			as = 1;

			for (int j = 0; j < vv[int(tolower(int(s[i])))].size(); j += 2)
			{

				string r = str;
				for (int k = 0; k < str.size(); k++)
				{
					double dd = eq(mp[r].first, mp[r].second, vv[int(tolower(int(s[i])))][j], vv[int(tolower(int(s[i])))][j + 1]);
					if (dd < mn)
						mn = dd;
					r.pop_back();
				}
				if (mnn > mn)
				{
					mnn = mn;
				}

			}
			if (mnn > x)
			{
				as = 1;
				ans++;
			}
		}
	}
	//if (as)
		cout << ans;

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
#define loop(i,n) for(int i = 0,_ = (n);i < _;i++)
#define lp(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.begin(),v.end()
#define omani dance();
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sz(v) (int)v.size()
#define uq(c) (c).resize(unique(all(c)) - (c).begin())
typedef long long ll;
#define clr(v,val) memset(v,val,sizeof v)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
void dance()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

bool comp(pair<int, int>x, pair<int, int>y)
{
	if (x.first == y.first) return x.second<y.second;
	return x.first>y.first;
}
void PLAY() {

	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);

	cout << fixed << setprecision(15);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
string s; ll n;

double eq(int x1, int y1, int x2, int y2)
{
	double dis;
	dis = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
	dis = sqrt(dis);
	return dis;
}
bool up(string s)
{
	for (int i = 0; i < s.size(); i++)
	{
		if (isupper(s[i]))return 1;
	}
	return 0;
}
vector <int> node[200000 + 9];
bool qq[250];
int main()
{
	omani

		int n, m;double  x;
	vector<vector<int>>vv(250);
	cin >> n >> m >> x; bool f = 0; int c = 0;
	map<string, pair<int, int>>mp; string str = ""; string s;
	char ch;
	for (int i = 1; i <=n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			cin >> ch;

			if (ch == 'S')
			{
				f = 1;

				str += "S";
				mp[str]=make_pair(i, j);
			}
			else
			{
				vv[int(ch)].push_back(i), vv[int(ch)].push_back(j);
				qq[ch] = 1;
			}
		}

	}

	int llll; cin >> llll;
	int ans = 0;
	cin >> s;
	map<char, int>mm;
	for (int i = 0; i < s.size(); i++)
		mm[s[i]]++;
	uq(s);
	if (up(s) && !f)
		return cout << -1, 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (qq[int(tolower(int(s[i])))] == 0&&s[i]!='S')
			return cout << -1, 0;
	}
	bool as = 0;

	for (int i = 0; i < s.size(); i++)
	{
		double mn = 9999999.9; double mnn = 9999999.9;
		if (isupper(s[i]) &&f)
		{
			as = 1;

			for (int j = 0; j < vv[int(tolower(int(s[i])))].size(); j += 2)
			{

				string r = str;
				for (int k = 0; k < str.size(); k++)
				{
					double dd = eq(mp[r].first, mp[r].second, vv[int(tolower(int(s[i])))][j], vv[int(tolower(int(s[i])))][j + 1]);
					if (dd < mn)
						mn = dd;
					r.pop_back();
				}
				if (mnn > mn)
				{
					mnn = mn;
				}

			}
			if (mnn > x)
			{
				as = 1;
				ans+=mm[toupper(s[i])];
			}
		}
	}
	//if (as)
		cout << ans;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;
	//if(arr[('S'-'a')+14].empty()) f1=1;
	for(int i='A';i<'Z';++i)
	{

			int f=1;
			for(auto v:arr[tolower(i)-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				//if(f) break;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=0;
						break;
					}
				}
			}
			 //if(!f)ans++;
			 mem[tolower(i)-'a'+14]=f;

	}
	//for(int i=0;i<63;++i) cout<<mem[i]<<endl;
	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			//cout<<mem[tolower(s[i])-'a'+14]<<endl;
			ans+=mem[tolower(s[i])-'a'+14];
		}
	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			if(mem[tolower(s[i])-'a'+14]!=-1)
			{
				//cout<<mem[tolower(s[i])-'a'+14]<<endl;
				ans+=mem[tolower(s[i])-'a'+14];
				continue;
			}
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				if(f) break;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
						break;
					}
				}
			}
			 if(!f)ans++;
			 mem[tolower(s[i])-'a'+14]=f-1;
		}

	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1;
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
					}
				}
			}
			if(!f) ans++;
		}

	}
	printf("%d\n",(ans&&!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans;
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if(isupper(s[i])&&!arr[('S'-'a')+14].empty())
		{
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <=pow(x,2))
					{
						f=1;
					}
				}
			}
			if(!f) ans++;
		}
	}
	printf("%d\n",(ans)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			if(mem[tolower(s[i])-'a'+14]!=-1)
			{
				ans+=mem[tolower(s[i])-'a'+14];
				continue;
			}
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
						break;
					}
				}
			}
			 ans+=f;
			 mem[tolower(s[i])-'a'+14]=f;
		}

	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1;
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
						break;
					}
				}
			}
			if(!f) ans++;
		}

	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			if(mem[tolower(s[i])-'a'+14]!=-1)
			{
				ans+=mem[tolower(s[i])-'a'+14];
			}
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
						break;
					}
				}
			}
			 ans+=f;
			 mem[tolower(s[i])-'a'+14]=f;
		}

	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			if(mem[tolower(s[i])-'a'+14]!=-1)
			{
				//cout<<mem[tolower(s[i])-'a'+14]<<endl;
				ans+=mem[tolower(s[i])-'a'+14];
				continue;
			}
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
						break;
					}
				}
			}
			 if(!f)ans++;
			 mem[tolower(s[i])-'a'+14]=f-1;
		}

	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;
	//if(arr[('S'-'a')+14].empty()) f1=1;
	for(int i='A';i<='Z';++i)
	{

			int f=1;
			for(auto v:arr[tolower(i)-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				//if(f) break;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=0;
						break;
					}
				}
			}
			 //if(!f)ans++;
			 mem[tolower(i)-'a'+14]=f;

	}
	//for(int i=0;i<63;++i) cout<<mem[i]<<endl;
	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			//cout<<s[i]<<endl;
			//cout<<mem[tolower(s[i])-'a'+14]<<endl;
			ans+=mem[tolower(s[i])-'a'+14];
		}
	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;
	if(arr[('S'-'a')+14].empty()) f1=1;
	for(int i='A';i<'Z';++i)
	{

			int f=1;
			for(auto v:arr[tolower(i)-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				//if(f) break;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=0;
						break;
					}
				}
			}
			 //if(!f)ans++;
			 mem[tolower(i)-'a'+14]=f;

	}
	//for(int i=0;i<63;++i) cout<<mem[i]<<endl;
	for(int i=0;i<q;++i)
	{
		if(arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			//cout<<mem[tolower(s[i])-'a'+14]<<endl;
			ans+=mem[tolower(s[i])-'a'+14];
		}
	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans;
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if(isupper(s[i])&&!arr[('S'-'a')+14].empty())
		{
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <=pow(x,2))
					{
						f=1;
					}
				}
			}
			if(!f) ans++;
		}
	}
	printf("%d\n",(ans)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1,mem[65];
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	memset(mem,-1,sizeof mem);
	scanf("%d%d%d",&n,&m,&x);

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			if(mem[tolower(s[i])-'a'+14]!=-1)
			{
				cout<<mem[tolower(s[i])-'a'+14]<<endl;
				ans+=mem[tolower(s[i])-'a'+14];
				continue;
			}
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
						break;
					}
				}
			}
			 if(!f)ans++;
			 mem[tolower(s[i])-'a'+14]=f-1;
		}

	}
	printf("%d\n",(!f1)?ans:-1);
}


#include<bits/stdc++.h>
using namespace std;
int n,m,x,q,ans,f1;
vector<pair<int,int>> arr[65];
char ch;
string s;
int main()
{
	scanf("%d%d%d",&n,&m,&x);
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
		{
			cin>>ch;
			arr[(ch-'a')+14].push_back({i,j});
		}
	}

	scanf("%d",&q);
	cin>>s;

	for(int i=0;i<q;++i)
	{
		if((isupper(s[i])&&arr[('S'-'a')+14].empty())||arr[tolower(s[i])-'a'+14].empty()){ f1=1; continue; }
		if(isupper(s[i]))
		{
			int f=0;
			for(auto v:arr[tolower(s[i])-'a'+14])
			{
				int a=v.first;
				int b=v.second;
				for(auto p:arr[('S'-'a')+14])
				{
					//cout<<pow((a-p.first),2)+pow((b-p.second),2)<<"  "<<pow(x,2)<<endl;
					if(pow((a-p.first),2)+pow((b-p.second),2) <= pow(x,2))
					{
						f=1;
					}
				}
			}
			if(!f) ans++;
		}

	}
	printf("%d\n",(!f1)?ans:-1);
}


#include <bits/stdc++.h> //printf("%.10lf\n",x);
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const long long int inf = 0x3f3f3f3f;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
typedef long long ll;

double eclidian(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(abs(x2-x1),2)+pow(abs(y2-y1),2));
}

map<char,int>in;
map<char,double>dis;
vector<pair<int,int> >shifts;

int main()
{

    ROCK;
    int n,m,x;cin>>n>>m>>x;
    char a[n][m];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c;cin>>c;
            a[i][j]=c;
            if(c=='S')shifts.push_back({i,j});
            in[tolower(c)]=1;
        }
    }

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c=a[i][j];
            double mndis=inf;
            for(auto x:shifts)
            {
                int px=x.first;int py=x.second;
                double ans=eclidian(i,j,px,py);
                if(ans<mndis)mndis=ans;
            }dis[c]=mndis;
        }
    }

    int q,cnt=0;cin>>q;string s;cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        if(isupper(s[i])&&(!shifts.size()||!in[tolower(s[i])])){cout<<-1<<endl;return 0;}
        if(islower(s[i])&&!in[s[i]]){cout<<-1<<endl;return 0;}
        if(isupper(s[i])&&dis[tolower(s[i])]>x)cnt++;
    }
    cout<<cnt;
    return 0;
}


#include <bits/stdc++.h> //printf("%.10lf\n",x);
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const long long int inf = 0x3f3f3f3f;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
typedef long long ll;

double eclidian(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(abs(x2-x1),2)+pow(abs(y2-y1),2));
}

vector<pair<int,int> >v[28];
map<char,int>in;
vector<pair<int,int> >shifts;

int main()
{

    ROCK;
    int n,m,x;cin>>n>>m>>x;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c;cin>>c;
            if(c=='S')shifts.push_back({i,j});
            else v[(int)c-97].push_back({i,j});
            in[c]=1;
        }
    }

    int q,cnt=0;cin>>q;
    string s;cin>>s;

    for(int i=0; i<s.size(); i++)
    {
        char c=s[i];
        if(!in[c]&&islower(c)){cout<<-1<<endl;return 0;}
        if(isupper(c)&&!shifts.size()){cout<<-1<<endl;return 0;}
        if(isupper(c))
        {
           double mndis=inf;
           c=tolower(c);
           for(auto x:v[(int)c-97]){
             int xc=x.first;int yc=x.second;
            for(auto k :shifts){
                int px=k.first;int py=k.second;
                double ans=eclidian(xc,yc,px,py);
                if(ans<mndis)mndis=ans;
            }
           }if(mndis>x)cnt++;
        }

    }cout<<cnt<<endl;

    return 0;
}


#include <bits/stdc++.h> //printf("%.10lf\n",x);
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const long long int inf = 0x3f3f3f3f;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
typedef long long ll;

double eclidian(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(abs(x2-x1),2)+pow(abs(y2-y1),2));
}

vector<pair<int,int> >v[28];
map<char,int>in;
vector<pair<int,int> >shifts;

int main()
{

    ROCK;
    int n,m,x;cin>>n>>m>>x;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c;cin>>c;
            if(c=='S')shifts.push_back({i,j});
            else v[(int)c-97].push_back({i,j});
            in[tolower(c)]=1;
        }
    }

    int q,cnt=0;cin>>q;
    string s;cin>>s;

    for(int i=0; i<s.size(); i++)
    {
        char c=s[i];
        if(!in[tolower(c)]){cout<<-1<<endl;return 0;}
        if(isupper(c)&&!shifts.size()){cout<<-1<<endl;return 0;}
        if(isupper(c))
        {
           double mndis=inf;c=tolower(c);
           for(auto x:v[(int)c-97]){
             int xc=x.first;int yc=x.second;
            for(auto k :shifts){
                int px=k.first;int py=k.second;
                double ans=eclidian(xc,yc,px,py);
                if(ans<mndis)mndis=ans;
            }
           }if(mndis>x)cnt++;
        }

    }cout<<cnt<<endl;

    return 0;
}


#include <bits/stdc++.h> //printf("%.10lf\n",x);
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const long long int inf = 0x3f3f3f3f;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
typedef long long ll;

double eclidian(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(abs(x2-x1),2)+pow(abs(y2-y1),2));
}

vector<pair<int,int> >v[28];
map<char,int>in;
vector<pair<int,int> >shifts;

int main()
{

    ROCK;
    int n,m,x;cin>>n>>m>>x;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c;cin>>c;
            if(c=='S')shifts.push_back({i,j});
            else v[(int)c-97].push_back({i,j});
            in[c]=1;
        }
    }

    int q,cnt=0;cin>>q;
    string s;cin>>s;

    for(int i=0; i<s.size(); i++)
    {
        char c=s[i];
        if(!in[islower(c)]){cout<<-1<<endl;return 0;}
        if(isupper(c)&&!shifts.size()){cout<<-1<<endl;return 0;}
        if(isupper(c))
        {
           double mndis=inf;c=tolower(c);
           for(auto x:v[(int)c-97]){
             int xc=x.first;int yc=x.second;
            for(auto k :shifts){
                int px=k.first;int py=k.second;
                double ans=eclidian(xc,yc,px,py);
                if(ans<mndis)mndis=ans;
            }
           }if(mndis>x)cnt++;
        }

    }cout<<cnt<<endl;

    return 0;
}


#include <bits/stdc++.h> //printf("%.10lf\n",x);
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const long long int inf = 0x3f3f3f3f;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
typedef long long ll;

double eclidian(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(abs(x2-x1),2)+pow(abs(y2-y1),2));
}

map<char,int>in;
map<char,double>dis;
vector<pair<int,int> >shifts;

int main()
{

    ROCK;
    int n,m,x;cin>>n>>m>>x;
    char a[n][m];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c;cin>>c;
            a[i][j]=c;
            if(c=='S')shifts.push_back({i,j});
            in[tolower(c)]=1;
        }
    }

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c=a[i][j];
            double mndis=inf;
            for(auto x:shifts)
            {
                int px=x.first;int py=x.second;
                double ans=eclidian(i,j,px,py);
                if(ans<mndis)mndis=ans;
            }if(mndis<dis[c]||dis[c]==0)dis[c]=mndis;
        }
    }

    int q,cnt=0;cin>>q;string s;cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        if(isupper(s[i])&&(!shifts.size()||!in[tolower(s[i])])){cout<<-1<<endl;return 0;}
        if(islower(s[i])&&!in[s[i]]){cout<<-1<<endl;return 0;}
        if(isupper(s[i])&&dis[tolower(s[i])]>x)cnt++;
    }
    cout<<cnt;
    return 0;
}


#include <bits/stdc++.h> //printf("%.10lf\n",x);
#define ROCK ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const long long int inf = 0x3f3f3f3f;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
typedef long long ll;

double eclidian(int x1,int y1,int x2,int y2)
{
    return sqrt(pow(abs(x2-x1),2)+pow(abs(y2-y1),2));
}

map<char,int>in;
map<char,double>dis;
vector<pair<int,int> >shifts;

int main()
{

    ROCK;
    int n,m,x;cin>>n>>m>>x;
    char a[n][m];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c;cin>>c;
            a[i][j]=c;
            if(c=='S')shifts.push_back({i,j});
            in[c]=1;
        }
    }

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            char c=a[i][j];
            double mndis=inf;
            for(auto x:shifts)
            {
                int px=x.first;int py=x.second;
                double ans=eclidian(i,j,px,py);
                if(ans<mndis)mndis=ans;
            }if(mndis<dis[c]||dis[c]==0)dis[c]=mndis;
        }
    }

    int q,cnt=0;cin>>q;string s;cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        if(isupper(s[i])&&(!shifts.size()||!in[tolower(s[i])])){cout<<-1<<endl;return 0;}
        if(islower(s[i])&&!in[s[i]]){cout<<-1<<endl;return 0;}
        if(isupper(s[i])&&dis[tolower(s[i])]>x)cnt++;
    }
    cout<<cnt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    double x;
    bool mark=false;
    cin>>n>>m>>x;
    vector<pair<int,int> >shift;

    char arr[n][m];

    for(int i=0 ;i<n ;i++)
    {
        for(int j=0 ;j<m ;j++)
        {
            cin>>arr[i][j];
            if(arr[i][j]=='S')
            {
                mark=true;
                shift.push_back({i,j});
            }
        }
    }

    int q,hand=0;
    cin>>q;

    string str;
    cin>>str;

    for(int k=0 ;k<q ;k++)
    {
        vector<pair<int,int> >idx;
        bool found=false;
        bool cntr=false;

       if(mark==false||islower(str[k]))
       {
            for(int i=0 ;i<n ;i++)
            {
                for(int j=0 ;j<m ;j++)
                {
                    if(str[k]==arr[i][j])
                        found=true;
                }
            }

             if(found==false)
               {
                   cout<<"-1"<<endl;
                  return 0;
               }
        }
      else
      {
        if(isupper(str[k]))
            str[k]+=32;

            for(int i=0 ;i<n ;i++)
            {
                for(int j=0 ;j<m ;j++)
                {
                    if(str[k]==arr[i][j])
                        {
                            found=true;
                            idx.push_back({i,j});

                        }
                }

            }

             if(found==false)
               {
                   cout<<"-1"<<endl;
                  return 0;
               }
               else
               {
                   for(int z=0 ;z<shift.size() ;z++)
                   {
                    for(int d=0 ;d<idx.size() ;d++)
                       {
                           if(sqrt(pow((idx[d].first)-(shift[z].first),2)+pow((idx[d].second)-(shift[z].second),2))<=x)
                              cntr=true;
                       }
                   }
                   if(cntr==false)
                     {hand++;}

               }

      }
    }
    cout<<hand<<endl;

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    double x;
    bool mark=false;
    cin>>n>>m>>x;
    vector<pair<int,int> >shift;

    char arr[n][m];

    for(int i=0 ;i<n ;i++)
    {
        for(int j=0 ;j<m ;j++)
        {
            cin>>arr[i][j];
            if(arr[i][j]=='S')
            {
                mark=true;
                shift.push_back({i,j});
            }
        }
    }

    int q,hand=0;
    cin>>q;

    string str;
    cin>>str;

    for(int k=0 ;k<q ;k++)
    {
        vector<pair<int,int> >idx;
        bool found=false;
        bool cntr=false;

       if(mark==false||islower(str[k]))
       {
            for(int i=0 ;i<n ;i++)
            {
                for(int j=0 ;j<m ;j++)
                {
                    if(str[k]==arr[i][j])
                        found=true;
                }
            }

             if(found==false)
               {
                   cout<<"-1"<<endl;
                  return 0;
               }
        }
      else
      {
        if(isupper(str[k]))
            str[k]+=32;

            for(int i=0 ;i<n ;i++)
            {
                for(int j=0 ;j<m ;j++)
                {
                    if(str[k]==arr[i][j])
                        {
                            found=true;
                 for(int z=0 ;z<shift.size() ;z++)
                   {
                    if(sqrt(pow((i)-(shift[z].first),2)+pow((j)-(shift[z].second),2))<=x)
                              cntr=true;
                   }

                        }
                }

            }
            if(cntr==false)
                     {hand++;}

             if(found==false)
               {
                   cout<<"-1"<<endl;
                  return 0;
               }

      }
    }
    cout<<hand<<endl;

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m;
	double x;
	cin >> n >> m >> x;
	vector<pair<int, int> >shift;

	char arr[n][m];

	for (int i = 0; i<n; i++)
	{
		for (int j = 0; j<m; j++)
		{
			cin >> arr[i][j];
			if (arr[i][j] == 'S')
			{
				shift.push_back({ i,j });
			}
		}
	}

	int q, hand = 0;
	cin >> q;

	string str;
	cin >> str;

	for (int k = 0; k<q; k++)
	{
		bool found = false;
		bool mark = false;

		for (int i = 0; i<n; i++)
		{
			for (int j = 0; j<m; j++)
			{

				if (str[k] == arr[i][j] || str[k] + 32 == arr[i][j])
				{
					found = true;

					if (isupper(str[k]))
					{
						if (shift.size() <= 0)
						{
							cout << "-1" << endl;
							return 0;
						}

						for (int z = 0; z<shift.size(); z++)
						{
						    if(i==shift[z].first&&j==shift[z].second)
                                continue;

							if (sqrt(pow(abs(i - (shift[z].first)), 2) + pow(abs(j - (shift[z].second)), 2)) <= x)
							{
								mark = true;
							}

						}
					}
					else
					{
						mark = true;

					}

				}

			}

		}
		if (found == false)
		{
			cout << "-1" << endl;
			return 0;

		}

		if (mark == false)
		{
			hand++;
		}

	}
	cout << hand << endl;

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    double x;
    bool mark=false;
    cin>>n>>m>>x;
    vector<pair<int,int> >shift;

    char arr[n][m];

    for(int i=0 ;i<n ;i++)
    {
        for(int j=0 ;j<m ;j++)
        {
            cin>>arr[i][j];
            if(arr[i][j]=='S')
            {
                mark=true;
                shift.push_back({i,j});
            }
        }
    }

    int q,hand=0;
    pair<int,int>idx;
    cin>>q;

    string str;
    cin>>str;

    for(int k=0 ;k<q ;k++)
    {
        bool found=false;
        int cntr=0;

       if(mark==false||islower(str[k]))
       {
            for(int i=0 ;i<n ;i++)
            {
                for(int j=0 ;j<m ;j++)
                {
                    if(str[k]==arr[i][j])
                        found=true;
                }
            }

             if(found==false)
               {
                   cout<<"-1"<<endl;
                  return 0;
               }
        }
      else
      {
        if(isupper(str[k]))
            str[k]+=32;

            for(int i=0 ;i<n ;i++)
            {
                for(int j=0 ;j<m ;j++)
                {
                    if(str[k]==arr[i][j])
                        {
                            found=true;
                            idx={i,j};
                            break;
                        }
                }
                 if(found)
                    break;
            }

             if(found==false)
               {
                   cout<<"-1"<<endl;
                  return 0;
               }
               else
               {
                   for(int z=0 ;z<shift.size() ;z++)
                   {
                       if(sqrt(pow((idx.first)-(shift[z].first),2)+pow((idx.second)-(shift[z].second),2))>x)
                           cntr++;
                   }
                   if(cntr==shift.size())
                     {hand++;}

               }

      }
    }
    cout<<hand<<endl;

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m;
	double x;
	cin >> n >> m >> x;
	vector<pair<int, int> >shift;

	char arr[n][m];

	for (int i = 0; i<n; i++)
	{
		for (int j = 0; j<m; j++)
		{
			cin >> arr[i][j];
			if (arr[i][j] == 'S')
			{
				shift.push_back({ i,j });
			}
		}
	}

	int q, hand = 0;
	cin >> q;

	string str;
	cin >> str;

	for (int k = 0; k<q; k++)
	{
		bool found = false;
		bool mark = false;

		for (int i = 0; i<n; i++)
		{
			for (int j = 0; j<m; j++)
			{

				if (str[k] == arr[i][j] || str[k] + 32 == arr[i][j])
				{
					found = true;

					if (isupper(str[k]))
					{
						if (shift.size() <= 0)
						{
							cout << "-1" << endl;
							return 0;
						}

						for (int z = 0; z<shift.size(); z++)
						{
						    if(i==shift[z].first&&j==shift[z].second)
                                continue;

							if (sqrt((abs(i - (shift[z].first)))*(abs(i - (shift[z].first))) + (abs(j - (shift[z].second)))*(abs(j - (shift[z].second)))) <= x)
							{
								mark = true;
							}

						}
					}
					else
					{
						mark = true;

					}

				}

			}

		}
		if (found == false)
		{
			cout << "-1" << endl;
			return 0;

		}

		if (mark == false)
		{
			hand++;
		}

	}
	cout << hand << endl;

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,m,x;
	cin>>n>>m>>x;
	vector<pair<int,int> >lama[123];
	bool visited[123]={false};

	char arr[n][m];
	vector<pair<int,int> >shift;

	for(int i=0 ;i<n ;i++)
    {
        for(int j=0 ;j<m ;j++)
        {
            cin>>arr[i][j];
            if(arr[i][j]=='S')
            {
               shift.push_back({i,j});
            }
            else
            {
                visited[arr[i][j]]=true;
                lama[arr[i][j]].push_back({i,j});

            }

        }
    }
	int t;
	cin>>t;

    string str;
    cin>>str;

    int freq[123]={0};

    for(int i=0 ;i<str.size() ;i++)
    {
        if(isupper(str[i]))
        {
            if(shift.size()==0)
            {
                cout<<"-1"<<endl;
                return 0;
            }
            str[i]+=32;
            freq[str[i]]++;
        }

        if(visited[str[i]]==false)
        {
            cout<<"-1"<<endl;
            return 0;
        }

    }
    int cnt=0;
    for(int i=97 ;i<123 ;i++)
    {
        double mini=INT_MAX;
        if(freq[i]>0)
        {
            for(int j=0 ;j<lama[i].size() ;j++)
            {

                for(int k=0 ;k<shift.size();k++)
                {
                    double dist=sqrt((shift[k].first-lama[i][j].first)*(shift[k].first-lama[i][j].first)+(shift[k].second-lama[i][j].second)*(shift[k].second-lama[i][j].second));
                        mini=min(mini,dist);
                }
            }

            if(mini>x)
                cnt+=freq[i];
        }
    }
    cout<<cnt<<endl;

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m;
	double x;
	cin >> n >> m >> x;
	vector<pair<int, int> >shift;

	char arr[n][m];

	for (int i = 0; i<n; i++)
	{
		for (int j = 0; j<m; j++)
		{
			cin >> arr[i][j];
			if (arr[i][j] == 'S')
			{
				shift.push_back({ i,j });
			}
		}
	}

	int q, hand = 0;
	cin >> q;

	string str;
	cin >> str;

	for (int k = 0; k<q; k++)
	{
		bool found = false;
		bool mark = false;

		for (int i = 0; i<n; i++)
		{
			for (int j = 0; j<m; j++)
			{

				if (str[k] == arr[i][j] || str[k] + 32 == arr[i][j])
				{
					found = true;

					if (isupper(str[k]))
					{
						if (shift.size() <= 0)
						{
							cout << "-1" << endl;
							return 0;
						}

						for (int z = 0; z<shift.size(); z++)
						{
						    if(i==shift[z].first&&j==shift[z].second)
                                continue;

							if (sqrt(pow(abs(i - (shift[z].first)), 2) + pow(abs(j - (shift[z].second)), 2)) <= x)
							{
								mark = true;
								break;
							}

						}
					}
					else
					{
						mark = true;

					}

				}

			}
			if(found)
                break;

		}
		if (found == false)
		{
			cout << "-1" << endl;
			return 0;

		}

		if (mark == false)
		{
			hand++;
		}

	}
	cout << hand << endl;

	return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m;
	double x;
	cin >> n >> m >> x;
	vector<pair<int, int> >shift;

	char arr[n][m];

	for (int i = 0; i<n; i++)
	{
		for (int j = 0; j<m; j++)
		{
			cin >> arr[i][j];
			if (arr[i][j] == 'S')
			{
				shift.push_back({ i,j });
			}
		}
	}

	int q, hand = 0;
	cin >> q;

	string str;
	cin >> str;

	for (int k = 0; k<q; k++)
	{
		bool found = false;
		bool mark = false;

		for (int i = 0; i<n; i++)
		{
			for (int j = 0; j<m; j++)
			{
				if (str[k] == arr[i][j] || str[k] + 32 == arr[i][j])
				{
					found = true;

					if (isupper(str[k]))
					{
						if (shift.size() <= 0)
						{
							cout << "-1" << endl;
							return 0;
						}

						for (int z = 0; z<shift.size(); z++)
						{
							if (sqrt(pow(abs(i - (shift[z].first)), 2) + pow(abs(j - (shift[z].second)), 2)) <= x)
							{
								mark = true;
							}

						}
					}
					else
					{
						mark = true;

					}

				}

			}

		}
		if (found == false)
		{
			cout << "-1" << endl;
			return 0;

		}

		if (mark == false)
		{
			hand++;
		}

	}
	cout << hand << endl;

	return 0;

}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
char a[30][30],txt[500001];
double dista[26];
int main(){
	int n,m;
	double x;
	cin>>n>>m>>x;
	vector<pair<int,int> >gullu;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='S'){gullu.push_back(make_pair(i,j));}
		}
	}
	for(int u=0;u<26;u++){
		double mini=n*n+m*m;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(char(u+'a')==a[i][j]){
					for(int k=0;k<gullu.size();k++){
						mini=min(mini,hypot((gullu[k].first-i),(gullu[k].second-j)));
					}
				}
			}
		}
		dista[u]=mini;
	}
	int q,flag=0,count=0;
	cin>>q;
	cin>>txt;
	//for(int i=0;i<26;i++){cout<<char(i+'a')<<" "<<dista[i]<<endl;}
	for(int u=0;txt[u];u++){
		flag=0;
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++){
				if(a[j][k]==txt[u]||toupper(a[j][k])==txt[u]){flag=1;break;}
			}
		}
		if(flag==0){cout<<-1;return 0;}
		if(isupper(txt[u])){
			if(gullu.size()==0){cout<<-1;return 0;}
			if(dista[txt[u]-'A']>x&&dista[txt[u]-'A']!=n*n+m*m){count++;}
		}
	}
	cout<<count;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
double dist(int i,int j,int k,int l){
	return sqrt((i-j)*(i-j)+(k-l)*(k-l));
}
int main(){
	int n,m;double x;
	cin>>n>>m>>x;
	vector<pair<int ,int> >gullu;
	char **a=new char*[n];
	for(int i=0;i<n;i++){
		a[i]=new char[m];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='S'){gullu.push_back(make_pair(i+1,j+1));}
		}
	}
	int q;
	cin>>q;
	char *txt=new char[q];
	cin>>txt;
	int notei=2000,notej=2000,count=0,flag=0;
	for(int i=0;txt[i];i++){
		flag=0;
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++){
				if(a[j][k]==txt[i]||toupper(a[j][k])==txt[i]){flag=1;break;}
			}
		}
		if(flag==0){cout<<-1;return 0;}
		if(isupper(txt[i])){
			if(gullu.size()==0){cout<<"-1";return 0;}
			for(int j=0;j<n;j++){
				for(int k=0;k<m;k++){
					if(txt[i]==toupper(a[j][k])){notej=k+1,notei=j+1;}
				}
			}
			double mini=dist(gullu[0].first,notei,gullu[0].second,notej);
			for(int g=1;g<gullu.size();g++){
				mini=min(mini,dist(gullu[g].first,notei,gullu[g].second,notej));

			}
			if(mini>x){count++;}
		}
	}
	cout<<count;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
double dist(int i,int j,int k,int l){
	return sqrt((i-j)*(i-j)+(k-l)*(k-l));
}
int main(){
	int n,m;double x;
	cin>>n>>m>>x;
	vector<pair<int ,int> >gullu;
	char **a=new char*[n];
	for(int i=0;i<n;i++){
		a[i]=new char[m];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='S'){gullu.push_back(make_pair(i+1,j+1));}
		}
	}
	int q;
	cin>>q;
	char *txt=new char[q];
	cin>>txt;
	int notei=2000,notej=2000,count=0,flag=0;
	for(int i=0;txt[i];i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++){
				if(a[j][k]==txt[i]||toupper(a[j][k])==txt[i]){flag=1;break;}
			}
		}
		if(flag==0){cout<<-1;return 0;}
		if(isupper(txt[i])){
			if(gullu.size()==0){cout<<"-1";return 0;}
			for(int j=0;j<n;j++){
				for(int k=0;k<m;k++){
					if(txt[i]==toupper(a[j][k])){notej=k+1,notei=j+1;}
				}
			}
			double mini=dist(gullu[0].first,notei,gullu[0].second,notej);
			for(int g=1;g<gullu.size();g++){
				mini=min(mini,dist(gullu[g].first,notei,gullu[g].second,notej));

			}
			if(mini>x){count++;}
		}
	}
	cout<<count;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
double dist(int i,int j,int k,int l){
	return sqrt((i-j)*(i-j)+(k-l)*(k-l));
}
int main(){
	int n,m;double x;
	cin>>n>>m>>x;
	vector<pair<int ,int> >gullu;
	char **a=new char*[n];
	for(int i=0;i<n;i++){
		a[i]=new char[m];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='S'){gullu.push_back(make_pair(i+1,j+1));}
		}
	}
	int q;
	cin>>q;
	char *txt=new char[q];
	cin>>txt;
	int notei=2000,notej=2000,count=0,flag=0;
	for(int i=0;txt[i];i++){
		flag=0;
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++){
				if(a[j][k]==txt[i]||toupper(a[j][k])==txt[i]){flag=1;break;}
			}
		}
		if(flag==0){cout<<-1;return 0;}
		if(isupper(txt[i])){
			if(gullu.size()==0){cout<<"-1";return 0;}
			double mini=sqrt(n*n+m*m);
			for(int j=0;j<n;j++){
				for(int k=0;k<m;k++){
					if((!(isupper(a[j][k]))&&txt[i]==toupper(a[j][k]))){notej=k+1,notei=j+1;}
					for(int g=0;g<gullu.size();g++){
						mini=min(mini,dist(gullu[g].first,notei,gullu[g].second,notej));
					}
				}
			}
			if(mini>x){count++;}
		}
	}
	cout<<count;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
double dist(int i,int j,int k,int l){
	return sqrt((i-j)*(i-j)+(k-l)*(k-l));
}
int main(){
	int n,m;double x;
	cin>>n>>m>>x;
	vector<pair<int ,int> >gullu;
	char **a=new char*[n];
	for(int i=0;i<n;i++){
		a[i]=new char[m];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='S'){gullu.push_back(make_pair(i+1,j+1));}
		}
	}
	int q;
	cin>>q;
	char *txt=new char[q];
	cin>>txt;
	int notei=2000,notej=2000,count=0,flag=0;
	for(int i=0;txt[i];i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<m;k++){
				if(a[j][k]==txt[i]||toupper(a[j][k])==txt[i]){flag=1;break;}
			}
		}
		if(flag==0){cout<<-1<<txt[i]<<" tss"<<endl;return 0;}
		if(isupper(txt[i])){
			if(gullu.size()==0){cout<<"-1";return 0;}
			for(int j=0;j<n;j++){
				for(int k=0;k<m;k++){
					if(txt[i]==toupper(a[j][k])){notej=k+1,notei=j+1;}
				}
			}
			double mini=dist(gullu[0].first,notei,gullu[0].second,notej);
			for(int g=1;g<gullu.size();g++){
				mini=min(mini,dist(gullu[g].first,notei,gullu[g].second,notej));

			}
			if(mini>x){count++;}
		}
	}
	cout<<count;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
char a[30][30],txt[500001];
double dista[26];
int main(){
	int n,m;
	double x;
	cin>>n>>m>>x;
	vector<pair<int,int> >gullu;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
			if(a[i][j]=='S'){gullu.push_back(make_pair(i,j));}
		}
	}
	for(int u=0;u<26;u++){
		double mini=n*n+m*m;
		int flag=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(char(u+'a')==a[i][j]){flag=1;
					for(int k=0;k<gullu.size();k++){
						mini=min(mini,hypot((gullu[k].first-i),(gullu[k].second-j)));
					}
				}
			}
		}
		if(flag==1){dista[u]=mini;}
		else{dista[u]=-1;}
	}
	int q,flag=0,count=0;
	cin>>q;
	cin>>txt;
	//for(int i=0;i<26;i++){cout<<char(i+'a')<<" "<<dista[i]<<endl;}
	for(int u=0;txt[u];u++){
		if(dista[tolower(txt[u])-'a']==-1){cout<<-1;return 0;}
		if(isupper(txt[u])){
			if(gullu.size()==0){cout<<-1;return 0;}
			if(dista[txt[u]-'A']>x&&dista[txt[u]-'A']!=n*n+m*m){count++;}
		}
	}
	cout<<count;
}


//Om Sree Sai Ram
#include <bits/stdc++.h>
using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
typedef long long ll;
void local(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
}

double euc(double a,double b,double c,double d){
	a = a-c;
	b = b-d;
	return sqrt(pow(a,2)+pow(b,2));
}

int main()
{
	local();
	double x;
	int H,W;
	cin>>H>>W;
	cin>>x;
	vector<string> ar(H);
	lp(i,H){
		cin>>ar[i];
	}
	vector<pair<int,int>> pos;
	unordered_map<char,vector<pair<int,int>>> st;
	lp(i,H){
		lp(j,W){
			if(ar[i][j]!='S')
			st[ar[i][j]].push_back (make_pair(i,j));
			else{
				pos.push_back({i,j});
			}
		}
	}
	int N;
	cin>>N;
	string s;
	cin>>s;
	int ans =0;
	vector<bool> dp(26,false);
	lp(i,N){
		if(st.find(tolower(s[i]))==st.end()){
			cout<<-1<<endl;
			return 0;
		}
		if(islower(s[i])){
			continue;
		}
		if(pos.empty()){
			cout<<-1<<endl;
			return 0;
		}

		if(dp[tolower(s[i])-'a']){
			continue;
		}

		auto vec = st[tolower(s[i])];
		double mD = INT_MAX;
		bool flag = false;
       for(auto v:vec){
		double r,c;

		r = v.first;
		c = v.second;
		lp(j,pos.size()){
			double distance = euc(r,c,pos[j].first,pos[j].second);
			mD = min(mD,distance);
			if(mD<=x){
				dp[tolower(s[i])-'a'] = true;
                flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	   }

		if(mD>x){

			ans++;
		}

	}
	cout<<ans<<endl;

}


//Om Sree Sai Ram
#include <bits/stdc++.h>
using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
typedef long long ll;
void local(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
}

double euc(double a,double b,double c,double d){
	a = a-c;
	b = b-d;
	return sqrt(pow(a,2)+pow(b,2));
}

int main()
{
	local();
	double x;
	int H,W;
	cin>>H>>W;
	cin>>x;
	vector<string> ar(H);
	lp(i,H){
		cin>>ar[i];
	}
	vector<pair<int,int>> pos;
	unordered_map<char,vector<pair<int,int>>> st;
	lp(i,H){
		lp(j,W){
			if(ar[i][j]!='S')
			st[ar[i][j]].push_back (make_pair(i,j));
			else{
				pos.push_back({i,j});
			}
		}
	}
	int N;
	cin>>N;
	string s;
	cin>>s;
	int ans =0;
	vector<bool> dp(26,false);
	vector<bool> used(26,false);
	lp(i,N){
		if(st.find(tolower(s[i]))==st.end()){
			cout<<-1<<endl;
			return 0;
		}
		if(islower(s[i])){
			continue;
		}
		if(pos.empty()){
			cout<<-1<<endl;
			return 0;
		}

		if(dp[tolower(s[i])-'a']){
			continue;
		}

		if(used[tolower(s[i]-'a')]){
			ans++;
			continue;
		}

		auto vec = st[tolower(s[i])];
		double mD = INT_MAX;
		bool flag = false;
       for(auto v:vec){
		double r,c;

		r = v.first;
		c = v.second;
		lp(j,pos.size()){
			double distance = euc(r,c,pos[j].first,pos[j].second);
			mD = min(mD,distance);
			if(mD<=x){
				dp[tolower(s[i])-'a'] = true;
                flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	   }

		if(mD>x){

			ans++;
		}
		used[tolower(s[i])-'a']=true;

	}
	cout<<ans<<endl;

}


//Om Sree Sai Ram
#include <bits/stdc++.h>
using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
typedef long long ll;
void local(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
}

double euc(double a,double b,double c,double d){
	a = a-c;
	b = b-d;
	return sqrt(pow(a,2)+pow(b,2));
}

int main()
{
	local();
	double x;
	int H,W;
	cin>>H>>W;
	cin>>x;
	vector<string> ar(H);
	lp(i,H){
		cin>>ar[i];
	}
	vector<pair<int,int>> pos;
	unordered_map<char,vector<pair<int,int>>> st;
	lp(i,H){
		lp(j,W){
			if(ar[i][j]!='S')
			st[ar[i][j]].push_back (make_pair(i,j));
			else{
				pos.push_back({i,j});
			}
		}
	}
	int N;
	cin>>N;
	string s;
	cin>>s;
	int ans =0;
	lp(i,N){
		if(st.find(tolower(s[i]))==st.end()){
			cout<<-1<<endl;
			return 0;
		}
		if(islower(s[i])){
			continue;
		}
		if(pos.empty()){
			cout<<-1<<endl;
			return 0;
		}

		auto vec = st[tolower(s[i])];
		double mD = INT_MAX;
       for(auto v:vec){
		double r,c;

		r = v.first;
		c = v.second;
		lp(j,pos.size()){
			double distance = euc(r,c,pos[j].first,pos[j].second);
			mD = min(mD,distance);
		}
	   }

		if(mD>x){

			ans++;
		}

	}
	cout<<ans<<endl;

}


//Om Sree Sai Ram
#include <bits/stdc++.h>
using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
typedef long long ll;
void local(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
}

double euc(double a,double b,double c,double d){
	a = a-c;
	b = b-d;
	return sqrt(pow(a,2)+pow(b,2));
}

int main()
{
	local();
	double x;
	int H,W;
	cin>>H>>W;
	cin>>x;
	vector<string> ar(H);
	lp(i,H){
		cin>>ar[i];
	}
	vector<pair<int,int>> pos;
	unordered_map<char,vector<pair<int,int>>> st;
	lp(i,H){
		lp(j,W){
			if(ar[i][j]!='S')
			st[ar[i][j]].push_back (make_pair(i,j));
			else{
				pos.push_back({i,j});
			}
		}
	}
	int N;
	cin>>N;
	string s;
	cin>>s;
	int ans =0;
	lp(i,N){
		if(st.find(tolower(s[i]))==st.end()){
			cout<<-1<<endl;
			return 0;
		}
		if(islower(s[i])){
			continue;
		}
		if(pos.empty()){
			cout<<-1<<endl;
			return 0;
		}

		auto vec = st[tolower(s[i])];
		double mD = INT_MAX;
		bool flag = false;
       for(auto v:vec){
		double r,c;

		r = v.first;
		c = v.second;
		lp(j,pos.size()){
			double distance = euc(r,c,pos[j].first,pos[j].second);
			mD = min(mD,distance);
			if(mD<x){
                flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	   }

		if(mD>x){

			ans++;
		}

	}
	cout<<ans<<endl;

}


//Om Sree Sai Ram
#include <bits/stdc++.h>
using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
typedef long long ll;
void local(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
}

double euc(double a,double b,double c,double d){
	a = a-c;
	b = b-d;
	return sqrt(pow(a,2)+pow(b,2));
}

int main()
{
	local();
	double x;
	int H,W;
	cin>>H>>W;
	cin>>x;
	vector<string> ar(H);
	lp(i,H){
		cin>>ar[i];
	}
	vector<pair<int,int>> pos;
	unordered_map<char,pair<int,int>> st;
	lp(i,H){
		lp(j,W){
			if(ar[i][j]!='S')
			st[ar[i][j]] = {i,j};
			else{
				pos.push_back({i,j});
			}
		}
	}
	int N;
	cin>>N;
	string s;
	cin>>s;
	int ans =0;
	lp(i,N){
		if(st.find(tolower(s[i]))==st.end()){
			cout<<-1<<endl;
			return 0;
		}
		if(islower(s[i])){
			continue;
		}
		if(pos.empty()){
			cout<<-1<<endl;
			return 0;
		}
		double r,c;

		r = st[tolower(s[i])].first;
		c = st[tolower(s[i])].second;
		double mD = INT_MAX;
		lp(j,pos.size()){
			double distance = euc(r,c,pos[j].first,pos[j].second);
			mD = min(mD,distance);
		}

		if(mD>x){

			ans++;
		}

	}
	cout<<ans<<endl;

}


//Om Sree Sai Ram
#include <bits/stdc++.h>
using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
typedef long long ll;
void local(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
}

double euc(double a,double b,double c,double d){
	a = a-c;
	b = b-d;
	return sqrt(pow(a,2)+pow(b,2));
}

int main()
{
	local();
	double x;
	int H,W;
	cin>>H>>W;
	cin>>x;
	vector<string> ar(H);
	lp(i,H){
		cin>>ar[i];
	}
	vector<pair<int,int>> pos;
	unordered_map<char,vector<pair<int,int>>> st;
	lp(i,H){
		lp(j,W){
			if(ar[i][j]!='S')
			st[ar[i][j]].push_back (make_pair(i,j));
			else{
				pos.push_back({i,j});
			}
		}
	}
	int N;
	cin>>N;
	string s;
	cin>>s;
	int ans =0;
	vector<bool> dp(26,false);
	vector<bool> used(26,false);
	lp(i,N){
		if(st.find(tolower(s[i]))==st.end()){
			cout<<-1<<endl;
			return 0;
		}
		if(islower(s[i])){
			continue;
		}
		if(pos.empty()){
			cout<<-1<<endl;
			return 0;
		}

		if(dp[tolower(s[i])-'a']){
			continue;
		}

		if(used[tolower(s[i])-'a']){
			ans++;
			continue;
		}

		auto vec = st[tolower(s[i])];
		double mD = INT_MAX;
		bool flag = false;
       for(auto v:vec){
		double r,c;

		r = v.first;
		c = v.second;
		lp(j,pos.size()){
			double distance = euc(r,c,pos[j].first,pos[j].second);
			mD = min(mD,distance);
			if(mD<=x){
				dp[tolower(s[i])-'a'] = true;
                flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	   }

		if(mD>x){

			ans++;
		}
		used[tolower(s[i])-'a']=true;

	}
	cout<<ans<<endl;

}


//Om Sree Sai Ram
#include <bits/stdc++.h>
using namespace std;

#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
typedef long long ll;
void local(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
}

double euc(double a,double b,double c,double d){
	a = a-c;
	b = b-d;
	return sqrt(pow(a,2)+pow(b,2));
}

int main()
{
	local();
	double x;
	int H,W;
	cin>>H>>W;
	cin>>x;
	vector<string> ar(H);
	lp(i,H){
		cin>>ar[i];
	}
	vector<pair<int,int>> pos;
	unordered_map<char,vector<pair<int,int>>> st;
	lp(i,H){
		lp(j,W){
			if(ar[i][j]!='S')
			st[ar[i][j]].push_back (make_pair(i,j));
			else{
				pos.push_back({i,j});
			}
		}
	}
	int N;
	cin>>N;
	string s;
	cin>>s;
	int ans =0;
	lp(i,N){
		if(st.find(tolower(s[i]))==st.end()){
			cout<<-1<<endl;
			return 0;
		}
		if(islower(s[i])){
			continue;
		}
		if(pos.empty()){
			cout<<-1<<endl;
			return 0;
		}

		auto vec = st[tolower(s[i])];
		double mD = INT_MAX;
		bool flag = false;
       for(auto v:vec){
		double r,c;

		r = v.first;
		c = v.second;
		lp(j,pos.size()){
			double distance = euc(r,c,pos[j].first,pos[j].second);
			mD = min(mD,distance);
			if(mD<=x){
                flag = true;
				break;
			}
		}
		if(flag){
			break;
		}
	   }

		if(mD>x){

			ans++;
		}

	}
	cout<<ans<<endl;

}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////
char keyboard[35][35];
int n, m;
vector<pair<int, int>> find(char x)
{
	vector<pair<int, int>>found;
	if (x >= 'A' && x <= 'Z')
		x = x + ('a' - 'A');

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (keyboard[i][j] == x)
				found.push_back({ i,j });
	return found;
}

int main()
{
	FIO;
	PIT(6);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	bool arr[30] = { 0 };
	set<char> chars;
	int x,Cap = 0;
	vector<pair<int, int>>shift;
	cin >> n >> m >> x;
	for(int i = 0 ; i <n;i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			if (x == 'S')
				shift.push_back({ i,j });
			else
				chars.insert(x);
			keyboard[i][j] = x;

			if (x >= 'A' && x <= 'Z')Cap++;
		}
	ll q,h = 0;
	bool cap = 0 , notf = 0;
	cin >> q;
	string word;
	cin >> word;
	for (auto i : word)
	{
		if (i >= 'A' && i <= 'Z')
			cap = 1;
		vector<pair<int, int>> f = find(i);
		if (!f.size() && x != 'S')
			notf = 1;
	}

	if ((cap && !shift.size()) || notf)
		cout << -1;
	else
	{
		for (auto c : chars)
		{
			bool f = 0;
			vector<pair<int, int>> pos = find(c);
			for (auto p : pos)
			{
				for (auto i : shift)
				{
					if (sqrt((i.first - p.first) * (i.first - p.first) +
						(i.second - p.second) * (i.second - p.second)) <= x)
						f = 1;
				}
			}
			if (!f)
				arr[c - 'a'] = 1;
		}

		for (auto i : word)
		{

			if (i >= 'A' && i <= 'Z')
			{
				if(arr[(i + ('a' - 'A')) - 'a'])
					h++;
			}
		}
		cout << h;
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////
char keyboard[35][35];
int n, m;
pair<int, int> find(char x)
{
	x = x + ('a' - 'A');
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (keyboard[i][j] == x)
				return { i,j };
}

int main()
{
	FIO;
	PIT(6);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int x,Cap = 0;
	vector<pair<int, int>>shift;
	cin >> n >> m >> x;
	for(int i = 0 ; i <n;i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			if (x == 'S')
				shift.push_back({ i,j });
			keyboard[i][j] = x;

			if (x >= 'A' && x <= 'Z')Cap++;
		}
	ll q,h = 0;
	bool cap = 0;
	cin >> q;
	string word;
	cin >> word;
	for (auto i : word)
		if (i >= 'A' && i <= 'Z')
			cap = 1;

	if (cap && !shift.size())
		cout << -1;
	else
	{

		for (auto i : word)
		{

			if (i >= 'A' && i <= 'Z')
			{
				pair<int, int> pos = find(i);
				bool f = 0;
				for (auto i : shift)
				{
					if (sqrt((i.first - pos.first) * (i.first - pos.first) +
						(i.second - pos.second) * (i.second - pos.second)) <= x)
						f = 1;
				}
				if (!f)
					h++;
			}
			cout << h;
		}
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////
char keyboard[35][35];
int n, m;
vector<pair<int, int>> find(char x)
{
	vector<pair<int, int>>found;
	if (x >= 'A' && x <= 'Z')
		x = x + ('a' - 'A');

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (keyboard[i][j] == x)
				found.push_back({ i,j });
	return found;
}

int main()
{
	FIO;
	PIT(6);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int x,Cap = 0;
	vector<pair<int, int>>shift;
	cin >> n >> m >> x;
	for(int i = 0 ; i <n;i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			if (x == 'S')
				shift.push_back({ i,j });
			keyboard[i][j] = x;

			if (x >= 'A' && x <= 'Z')Cap++;
		}
	ll q,h = 0;
	bool cap = 0 , notf = 0;
	cin >> q;
	string word;
	cin >> word;
	for (auto i : word)
	{
		if (i >= 'A' && i <= 'Z')
			cap = 1;
		vector<pair<int, int>> f = find(i);
		if (!f.size() && x != 'S')
			notf = 1;
	}

	if ((cap && !shift.size()) || notf)
		cout << -1;
	else
	{
		for (auto i : word)
		{

			if (i >= 'A' && i <= 'Z')
			{
				vector<pair<int, int>> pos = find(i);
				bool f = 0;
				for (auto p : pos)
				{
					for (auto i : shift)
					{
						if (sqrt((i.first - p.first) * (i.first - p.first) +
							(i.second - p.second) * (i.second - p.second)) <= x)
							f = 1;
					}
				}
				if (!f)
					h++;
			}
		}
		cout << h;
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////
char keyboard[35][35];
int n, m;
pair<int, int> find(char x)
{
	x = x + ('a' - 'A');
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (keyboard[i][j] == x)
				return { i,j };
}

int main()
{
	FIO;
	PIT(6);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int x,Cap = 0;
	vector<pair<int, int>>shift;
	cin >> n >> m >> x;
	for(int i = 0 ; i <n;i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			if (x == 'S')
				shift.push_back({ i,j });
			keyboard[i][j] = x;

			if (x >= 'A' && x <= 'Z')Cap++;
		}
	ll q,h = 0;
	cin >> q;
	if (!Cap)
		cout << 0;
	else if (!shift.size())
		cout << -1;
	else
	{
		while (q--)
		{
			char c;
			cin >> c;
			if (c >= 'A' && c <= 'Z')
			{
				pair<int, int> pos = find(c);
				bool f = 0;
				for (auto i : shift)
				{
					if (sqrt((i.first - pos.first) * (i.first - pos.first) +
						(i.second - pos.second) * (i.second - pos.second)) <= x)
						f = 1;
				}
				if (!f)
					h++;
			}
		}
		cout << h;
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////
char keyboard[35][35];
int n, m;
pair<int, int> find(char x)
{
	x = x + ('a' - 'A');
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (keyboard[i][j] == x)
				return { i,j };
}

int main()
{
	FIO;
	PIT(6);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int x;
	vector<pair<int, int>>shift;
	cin >> n >> m >> x;
	for(int i = 0 ; i <n;i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			if (x == 'S')
				shift.push_back({ i,j });
			keyboard[i][j] = x;
		}
	ll q,h = 0;
	cin >> q;
	if (!shift.size())
		cout << -1;
	else
	{
		while (q--)
		{
			char c;
			cin >> c;
			if (c >= 'A' && c <= 'Z')
			{
				pair<int, int> pos = find(c);
				bool f = 0;
				for (auto i : shift)
				{
					if (sqrt((i.first - pos.first) * (i.first - pos.first) +
						(i.second - pos.second) * (i.second - pos.second)) <= x)
						f = 1;
				}
				if (!f)
					h++;
			}
		}
		cout << h;
	}
}


//#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <complex>
#include <math.h>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
using namespace std;

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PIT(x) cout.setf(ios::fixed);cout.setf(ios::showpoint);cout.precision(x);
#define ll long long
#define MOD (ll)(1e9 + 7)
#define Point complex<double>
#define eps (1e-9)
#define pi acos(-1)
#define inf 2e9

ll fastPower(ll b, ll p)
{
	if (!p)
		return 1;

	ll answer = fastPower(b, p / 2);
	answer = ((answer % MOD) * (answer % MOD)) % MOD;
	if (p % 2) answer = ((answer % MOD) * (b % MOD)) % MOD;

	return answer;
}

ll GCD(ll a, ll b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}
/////////////////////////////////////////////////////////////
char keyboard[35][35];
int n, m;
pair<int, int> find(char x)
{
	if (x >= 'A' && x <= 'Z')
		x = x + ('a' - 'A');

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (keyboard[i][j] == x)
				return { i,j };
	return { -1,-1 };
}

int main()
{
	FIO;
	PIT(6);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int x,Cap = 0;
	vector<pair<int, int>>shift;
	cin >> n >> m >> x;
	for(int i = 0 ; i <n;i++)
		for (int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			if (x == 'S')
				shift.push_back({ i,j });
			keyboard[i][j] = x;

			if (x >= 'A' && x <= 'Z')Cap++;
		}
	ll q,h = 0;
	bool cap = 0 , notf = 0;
	cin >> q;
	string word;
	cin >> word;
	for (auto i : word)
	{
		if (i >= 'A' && i <= 'Z')
			cap = 1;
		if (find(i).first == -1 && x != 'S')
			notf = 1;
	}

	if ((cap && !shift.size()) || notf)
		cout << -1;
	else
	{
		for (auto i : word)
		{

			if (i >= 'A' && i <= 'Z')
			{
				pair<int, int> pos = find(i);
				bool f = 0;
				for (auto i : shift)
				{
					if (sqrt((i.first - pos.first) * (i.first - pos.first) +
						(i.second - pos.second) * (i.second - pos.second)) <= x)
						f = 1;
				}
				if (!f)
					h++;
			}
		}
		cout << h;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
using namespace std;
double pi = acos(-1);
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
//#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void PrintNumber(int n, int len)
{
    if (!len)
        return;
    cout << (n & 1);
}
void PrintAllSubset(int n)
{
    f(int i = 0; i < (1 << n); i++)
    {
        PrintNumber(i, n);
        cout << endl;
    }
}

//int a[1000003];
set<string>x;
int main()
{
    //Open();
    //freopen("mex.in","r",stdin);
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,m,w;
    cin>>n>>m>>w;
    char a[33][33];
    vector<pair<int,int>>s;
    f(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='S')
            {
                s.push_back({i,j});
            }
        }
    }

    int q;
    cin>>q;
    string x;
    cin>>x;
    int c=0;
    map<char,int>mp;
    f(int u=0; u<x.size(); u++)
    {
        char r=tolower(x[u]);
        bool pp=0;
        f(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(a[i][j]==r)
                {
                    pp=1;
                }
            }
        }
        if(!pp)
        {
            cout<<-1;
            return 0;
        }
        if(isupper(x[u]))
        {
            x[u]=tolower(x[u]);
            if(mp[x[u]]==1)
            {
                c++;
                continue;
            }
            if(mp[x[u]]==2)
            {
                continue;
            }
            if(s.size()==0)
            {
                cout<<-1<<endl;
                return 0;
            }
            int z=INT_MAX;
            f(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    if(a[i][j]==x[u])
                    {
                        int y=INT_MAX;
                        f(int k=0; k<s.size(); k++)
                        {
                            y=min(abs(s[k].first-i)*abs(s[k].first-i)+abs(s[k].second-j)*abs(s[k].second-j),y);

                        }
                        z=min(z,y);
                    }

                }
            }
            if(z>w*w)
            {
                c++;
                //cout<<x[u]<<" ";
                mp[x[u]]=1;
            }
            else
                mp[x[u]]=2;
        }
    }
    cout<<c<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
using namespace std;
double pi = acos(-1);
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
//#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void PrintNumber(int n, int len)
{
    if (!len)
        return;
    cout << (n & 1);
}
void PrintAllSubset(int n)
{
    f(int i = 0; i < (1 << n); i++)
    {
        PrintNumber(i, n);
        cout << endl;
    }
}

//int a[1000003];
set<string>x;
int main()
{
    //Open();
    //freopen("mex.in","r",stdin);
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,m,w;
    cin>>n>>m>>w;
    char a[33][33];
    vector<pair<int,int>>s;
    f(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='S')
            {
                s.push_back({i,j});
            }
        }
    }

    int q;
    cin>>q;
    string x;
    cin>>x;
    int c=0;
    map<char,int>mp;
    f(int u=0; u<x.size(); u++)
    {
        char r=tolower(x[u]);
        bool pp=0;
        f(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(a[i][j]==r)
                {
                    pp=1;
                }
            }
        }
        if(!pp)
        {
            cout<<-1;
            return 0;
        }
        if(isupper(x[u]))
        {
            if(s.size()==0)
            {
                cout<<-1<<endl;
                return 0;
            }
            int z=INT_MAX;
            f(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    x[u]=tolower(x[u]);
                    if(a[i][j]==x[u])
                    {
                        int y=INT_MAX;
                        f(int k=0; k<s.size(); k++)
                        {
                            y=min(abs(s[k].first-i)*abs(s[k].first-i)+abs(s[k].second-j)*abs(s[k].second-j),y);

                        }
                        z=min(z,y);
                    }

                }
            }
            if(z>w*w&&!mp[x[u]])
                            {
                                c++;
                                //cout<<x[u]<<" ";
                                //mp[x[u]]++;
                            }
        }
    }
    cout<<c<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
using namespace std;
double pi = acos(-1);
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
//#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void PrintNumber(int n, int len)
{
    if (!len)
        return;
    cout << (n & 1);
}
void PrintAllSubset(int n)
{
    f(int i = 0; i < (1 << n); i++)
    {
        PrintNumber(i, n);
        cout << endl;
    }
}

//int a[1000003];
set<string>x;
int main()
{
    //Open();
    //freopen("mex.in","r",stdin);
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,m,w;
    cin>>n>>m>>w;
    char a[33][33];
    vector<pair<int,int>>s;
    f(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='S')
            {
                s.push_back({i,j});
            }
        }
    }

    int q;
    cin>>q;
    string x;
    cin>>x;
    int c=0;
    int mp[200]={0};
    f(int u=0; u<x.size(); u++)
    {
        char r=tolower(x[u]);
        bool pp=0;
        f(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(a[i][j]==r)
                {
                    pp=1;
                }
            }
        }
        if(!pp)
        {
            cout<<-1;
            return 0;
        }
        if(isupper(x[u]))
        {
            if(s.size()==0)
            {
                cout<<-1<<endl;
                return 0;
            }
            int z=INT_MAX;
            f(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    x[u]=tolower(x[u]);
                    if(a[i][j]==x[u])
                    {
                        int y=INT_MAX;
                        f(int k=0; k<s.size(); k++)
                        {
                            y=min(abs(s[k].first-i)*abs(s[k].first-i)+abs(s[k].second-j)*abs(s[k].second-j),y);

                        }
                        z=min(z,y);
                    }

                }
            }
            if(z>w*w&&!mp[x[u]])
                            {
                                c++;
                                //cout<<x[u]<<" ";
                                //mp[x[u]]++;
                            }
        }
    }
    cout<<c<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
using namespace std;
double pi = acos(-1);
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
//#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void PrintNumber(int n, int len)
{
    if (!len)
        return;
    cout << (n & 1);
}
void PrintAllSubset(int n)
{
    f(int i = 0; i < (1 << n); i++)
    {
        PrintNumber(i, n);
        cout << endl;
    }
}

//int a[1000003];
set<string>x;
int main()
{
    //Open();
    //freopen("mex.in","r",stdin);
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,m,w;
    cin>>n>>m>>w;
    char a[33][33];
    vector<pair<int,int>>s;
    f(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='S')
            {
                s.push_back({i,j});
            }
        }
    }

    int q;
    cin>>q;
    string x;
    cin>>x;
    int c=0;
    map<char,int>mp;
    f(int u=0; u<x.size(); u++)
    {
        char r=tolower(x[u]);
        bool pp=0;
        f(int i=1; i<=n; i++)
        {
            for(int j=1; j<=m; j++)
            {
                if(a[i][j]==r)
                {
                    pp=1;
                }
            }
        }
        if(!pp)
        {
            cout<<-1;
            return 0;
        }
        if(isupper(x[u]))
        {
            if(s.size()==0)
            {
                cout<<-1<<endl;
                return 0;
            }
            f(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    x[u]=tolower(x[u]);
                    if(a[i][j]==x[u])
                    {
                        int y=INT_MAX;
                        f(int k=0; k<s.size(); k++)
                        {
                            y=min(abs(s[k].first-i)*abs(s[k].first-i)+abs(s[k].second-j)*abs(s[k].second-j),y);

                        }
                        if(y>w*w&&!mp[x[u]])
                            {
                                c++;
                                mp[x[u]]++;
                            }
                    }
                }
            }
        }
    }
    cout<<c<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define f for
#define ll long long
#define ull unsigned long long
#define endl "\n"
using namespace std;
double pi = acos(-1);
void Open()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}
//#define all(a) a.begin(), a.end()
ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}
void PrintNumber(int n, int len)
{
    if (!len)
        return;
    cout << (n & 1);
}
void PrintAllSubset(int n)
{
    f(int i = 0; i < (1 << n); i++)
    {
        PrintNumber(i, n);
        cout << endl;
    }
}

//int a[1000003];
set<string>x;
int main()
{
    //Open();
    //freopen("mex.in","r",stdin);
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int n,m,w;
    cin>>n>>m>>w;
    char a[33][33];
    vector<pair<int,int>>s;
    f(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='S')
            {
                s.push_back({i,j});
            }
        }
    }

    int q;
    cin>>q;
    string x;
    cin>>x;
    int c=0;
    f(int u=0; u<x.size(); u++)
    {
        char r=tolower(x[u]);
        bool pp=0;
        f(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(a[i][j]==r)
            {
               pp=1;
            }
        }
    }
    if(!pp)
    {
        cout<<-1;
        return 0;
    }
        if(isupper(x[u]))
        {
            if(s.size()==0)
            {
                cout<<-1<<endl;
                return 0;
            }
            f(int i=1; i<=n; i++)
            {
                for(int j=1; j<=m; j++)
                {
                    x[u]=tolower(x[u]);
                    if(a[i][j]==x[u])
                    {
                        int y=INT_MAX;
                        f(int k=0;k<s.size();k++)
                        {
                            y=min(abs(s[k].first-i)*abs(s[k].first-i)+abs(s[k].second-j)*abs(s[k].second-j),y);

                        }
                        if(y>w*w)c++;
                    }
                }
            }
        }
    }
    cout<<c<<endl;
}


//#include <x86_64-w64-mingw32\32\bits\stdc++.h>
#include <map>
#include<vector>
#include <math.h>
#include <iostream>
using namespace std;

int kdist(pair<int,int> a, pair<int,int> b)
{
    float x1,y1,x2,y2;
    x1 = a.first;
    y1 = a.second;
    x2 = b.first;
    y2 = b.second;
     int dist = pow((x1-x2),2) + pow((y1-y2),2);

     return dist;
}

int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int count = 0;
	int n,m,x;
    cin>>n>>m>>x;
    string s;
    map<char , vector<pair<int,int> > >charmap;
    for(int i=0;i<n;++i)
    {
        cin>>s;
        for(int j=0;j<m;++j)
        {

            charmap[s[j]].push_back(make_pair(i,j));
        }
    }
    int q;
    string query;
    cin>>q;
    cin>>query;
    // spof condition applies
    for(int i=0;i<q;++i)
    {
        bool onehand = false;
        char ch = query[i];
        if(ch >='a' && ch<='z')
        {
            if(charmap[ch].size() == 0)
            {
                cout<<(-1);
                return 0;
            }
        }  // lowercase done
        else if(ch >='A' && ch <= 'Z')
        {
            if( (charmap[ch].size() == 0) || (ch == 'S'))
            {
               ch = ch + 32;
               if( (charmap[ch].size() == 0) || (charmap['S'].size() == 0))
                    {
                        cout<<(-1);
                        return 0;
                    } // cant type the character
                else
                {
                    // now check the distance of all lowercase keys from all s
                    for(int k = 0;k<charmap[ch].size();++k)
                    {
                        for(int l = 0;l<charmap['S'].size();++l)
                        {
                          if(kdist(charmap[ch][k],charmap['S'][l]) <= (x*x))
                             {
                                 onehand =  true;
                                 break;
                             }
                        }
                        if(onehand == true)
                        {
                            break;
                        }

                    }
                    if(onehand == false)
                    count++;
                }

            } // only problem when key does no exist
        }

    }
    cout<<count;

	// your code goes here
	return 0;

}


//#include <x86_64-w64-mingw32\32\bits\stdc++.h>
#include <map>
#include<vector>
#include <math.h>
#include <iostream>
#include <set>
using namespace std;

int kdist(pair<int,int> a, pair<int,int> b)
{
    float x1,y1,x2,y2;
    x1 = a.first;
    y1 = a.second;
    x2 = b.first;
    y2 = b.second;
     int dist = pow((x1-x2),2) + pow((y1-y2),2);

     return dist;
}

int main()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int count = 0;
	int n,m,x;
    cin>>n>>m>>x;
    string s;
    map<char , vector<pair<int,int> > >charmap;
    for(int i=0;i<n;++i)
    {
        cin>>s;
        for(int j=0;j<m;++j)
        {

            charmap[s[j]].push_back(make_pair(i,j));
        }
    }
    int q;
    string query;
    cin>>q;
    cin>>query;
    map<char,int>freq;
    for(int i=0;i<query.size();++i)
    {
        freq[query[i]]++;
    }
    // spof condition applies
    for(map<char,int>::iterator sit = freq.begin();sit!=freq.end();sit++)

    {
        bool onehand = false;
        char ch = (sit->first);
        if(ch >='a' && ch<='z')
        {
            if(charmap[ch].size() == 0)
            {
                cout<<(-1);
                return 0;
            }
        }  // lowercase done
        else if(ch >='A' && ch <= 'Z')
        {
            if(charmap[ch].size() == 0 || (ch == 'S'))
            {
               ch = ch + 32;
               if( (charmap[ch].size() == 0) || (charmap['S'].size() == 0))
                    {
                        cout<<(-1);
                        return 0;
                    } // cant type the character
                else
                {
                    // now check the distance of all lowercase keys from all s
                    for(int k = 0;k<charmap[ch].size();++k)
                    {
                        for(int l = 0;l<charmap['S'].size();++l)
                        {
                          if(kdist(charmap[ch][k],charmap['S'][l]) <= (x*x))
                             {
                                 onehand =  true;
                                 break;
                             }
                        }
                        if(onehand == true)
                        {
                            break;
                        }

                    }
                    if(onehand == false)
                    count+=sit->second;
                }

            } // only problem when key does no exist
        }

    }
    cout<<count;

	// your code goes here
	return 0;

}


//#include <x86_64-w64-mingw32\32\bits\stdc++.h>
#include <map>
#include<vector>
#include <math.h>
#include <iostream>
#include <set>
using namespace std;

int kdist(pair<int,int> a, pair<int,int> b)
{
    float x1,y1,x2,y2;
    x1 = a.first;
    y1 = a.second;
    x2 = b.first;
    y2 = b.second;
     int dist = pow((x1-x2),2) + pow((y1-y2),2);

     return dist;
}

int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int count = 0;
	int n,m,x;
    cin>>n>>m>>x;
    string s;
    map<char , vector<pair<int,int> > >charmap;
    for(int i=0;i<n;++i)
    {
        cin>>s;
        for(int j=0;j<m;++j)
        {

            charmap[s[j]].push_back(make_pair(i,j));
        }
    }
    int q;
    string query;
    cin>>q;
    cin>>query;
    map<char,int>freq;
    for(int i=0;i<query.size();++i)
    {
        freq[query[i]]++;
    }
    // spof condition applies
    for(map<char,int>::iterator sit = freq.begin();sit!=freq.end();sit++)

    {
        bool onehand = false;
        char ch = (sit->first);
        if(ch >='a' && ch<='z')
        {
            if(charmap[ch].size() == 0)
            {
                cout<<(-1);
                return 0;
            }
        }  // lowercase done
        else if(ch >='A' && ch <= 'Z')
        {
            if(charmap[ch].size() == 0 || (ch == 'S'))
            {
               ch = ch + 32;
               if( (charmap[ch].size() == 0) || (charmap['S'].size() == 0))
                    {
                        cout<<(-1);
                        return 0;
                    } // cant type the character
                else
                {
                    // now check the distance of all lowercase keys from all s
                    for(int k = 0;k<charmap[ch].size();++k)
                    {
                        for(int l = 0;l<charmap['S'].size();++l)
                        {
                          if(kdist(charmap[ch][k],charmap['S'][l]) <= (x*x))
                             {
                                 onehand =  true;
                                 break;
                             }
                        }
                        if(onehand == true)
                        {
                            break;
                        }

                    }
                    if(onehand == false)
                    count+=sit->second;
                }

            } // only problem when key does no exist
        }

    }
    cout<<count;

	// your code goes here
	return 0;

}


//#include <x86_64-w64-mingw32\32\bits\stdc++.h>
#include <map>
#include<vector>
#include <math.h>
#include <iostream>
#include <set>
using namespace std;

int kdist(pair<int,int> a, pair<int,int> b)
{
    float x1,y1,x2,y2;
    x1 = a.first;
    y1 = a.second;
    x2 = b.first;
    y2 = b.second;
     int dist = pow((x1-x2),2) + pow((y1-y2),2);

     return dist;
}

int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    int count = 0;
	int n,m,x;
    cin>>n>>m>>x;
    string s;
    map<char , vector<pair<int,int> > >charmap;
    for(int i=0;i<n;++i)
    {
        cin>>s;
        for(int j=0;j<m;++j)
        {

            charmap[s[j]].push_back(make_pair(i,j));
        }
    }
    int q;
    string query;
    cin>>q;
    cin>>query;
    set<char> freq;
    for(int i=0;i<query.size();++i)
    {
        freq.insert(query[i]);
    }
    // spof condition applies
    for(set<char>::iterator sit = freq.begin();sit!=freq.end();sit++)

    {
        bool onehand = false;
        char ch = *sit;
        if(ch >='a' && ch<='z')
        {
            if(charmap[ch].size() == 0)
            {
                cout<<(-1);
                return 0;
            }
        }  // lowercase done
        else if(ch >='A' && ch <= 'Z')
        {
            if(charmap[ch].size() == 0 || (ch == 'S'))
            {
               ch = ch + 32;
               if( (charmap[ch].size() == 0) || (charmap['S'].size() == 0))
                    {
                        cout<<(-1);
                        return 0;
                    } // cant type the character
                else
                {
                    // now check the distance of all lowercase keys from all s
                    for(int k = 0;k<charmap[ch].size();++k)
                    {
                        for(int l = 0;l<charmap['S'].size();++l)
                        {
                          if(kdist(charmap[ch][k],charmap['S'][l]) <= (x*x))
                             {
                                 onehand =  true;
                                 break;
                             }
                        }
                        if(onehand == true)
                        {
                            break;
                        }

                    }
                    if(onehand == false)
                    count++;
                }

            } // only problem when key does no exist
        }

    }
    cout<<count;

	// your code goes here
	return 0;

}