#include <bits/stdc++.h>
using namespace std;
int main() {
int a,a2,num,num2,cnt=0,len,ans1,ans2;
char b[1000][1000];
string c;
cin >> a ;
cin >> a2;
for(int i=0;i<100;i++){
for(int j=0;j<100;j++){
b[i][j]='0';
}
}
for(int i=1;i<=a;i++){
for(int j=1;j<=a2;j++){
cin >> b[i][j];
if(b[i][j]>='A'&&b[i][j]<='Z'){
b[i][j]=b[i][j]+32;
}
}
}
cin >> c;
len=c.length();
//cout << len <<endl;
for(int i=0;i<len;i++){
if(c[i]>='A'&&c[i]<='Z'){
c[i]=c[i]+32;
}
}
if(len==1){
for(int i=1;i<=a;i++){
for(int j=1;j<=a2;j++){
if(b[i][j]==c[0]){
cout << i << " " << j<<endl;
cout << i << " " << j<<endl;
return 0;
}
}
}
}
if(a==1 && a2==1){
//cout << b[1][1] << " "<< c[0]<< endl;
if(b[1][1]==c[0]){
cout << "1 1"<< endl;
cout << "1 1"<< endl;
return 0;
}
}
for(int i=1;i<=a;i++){
for(int j=1;j<=a;j++){
if(b[i][j]==c[0]){
cnt=0;
ans1=i;
ans2=j;
num=i;
num2=j;
while(1){//正右
//cout <<"in1"<< endl;
num2--;
cnt++;
if(b[num][num2]=='0'){
break;
}
else if(b[num][num2]!=c[cnt]){
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
cnt=0;
num=i;
num2=j;
while(1){//正下
//cout <<"in2"<< endl;
num++;
cnt++;
if(b[num][num2]=='0'){
break;
}
else if(b[num][num2]!=c[cnt]){
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
cnt=0;
num=i;
num2=j;
while(1){//正左
//cout <<"in3"<< endl;
num2++;
cnt++;
if(b[num][num2]=='0'){
//cout << "inn";
break;
}
else if(b[num][num2]!=c[cnt]){
//cout << b[num][num2]<< " "<< c[cnt]<< endl;
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
cnt=0;
num=i;
num2=j;
while(1){//正上
//cout <<"in4"<< endl;
num--;
cnt++;
if(b[num][num2]=='0'){
break;
}
else if(b[num][num2]!=c[cnt]){
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
cnt=0;
num=i;
num2=j;
while(1){//左上
//cout <<"in5"<< endl;
num--;
num2--;
cnt++;
if(b[num][num2]=='0'){
break;
}
else if(b[num][num2]!=c[cnt]){
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
cnt=0;
num=i;
num2=j;
while(1){//左下
//cout <<"in6"<< endl;
num++;
num2--;
cnt++;
if(b[num][num2]=='0'){
break;
}
else if(b[num][num2]!=c[cnt]){
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
cnt=0;
num=i;
num2=j;
while(1){//右下
//cout <<"in7"<< endl;
num++;
num2++;
cnt++;
if(b[num][num2]=='0'){
break;
}
else if(b[num][num2]!=c[cnt]){
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
cnt=0;
num=i;
num2=j;
while(1){//右上
//cout <<"in8"<< endl;
num--;
num2++;
cnt++;
if(b[num][num2]=='0'){
break;
}
else if(b[num][num2]!=c[cnt]){
break;
}
else if(cnt==len-1&&b[num][num2]==c[cnt]){
cout << ans1 <<" "<<ans2<<endl;
cout << num << " "<< num2<< endl;
return 0;
}
}
}
}
}
cout << "NO";
}