#include<bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define ios ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
using namespace std;
int n,m;
string str;
struct node
{
int type;//1 string 2 obj
string t;
node(){}
node(string tem)
{
type=1;
t=tem;
}
map<string,node>v;
};
/*void pro()
{
for(int i=0;i<str.length()-1;i++)
if(str[i]=='\\'&&str[i+1]=='"'||str[i]=='\\'&&str[i+1]=='\\')
str.erase(i,1);
}*/
string get_str(int &k)
{
string w="";
k++;
while(str[k]!='"')
{
if(str[k]=='\\')
{
w+=str[k+1];
k+=2;
}
else
{
w+=str[k];
k++;
}
//cout<<w<<endl;
}
k++;
//cout<<w<<endl;
return w;
}
node work_obj(int &k);
void work_kv(node &obj,int &k)
{
string key=get_str(k);
//cout<<key<<endl;
while(str[k]!=','&&str[k]!='}')
{
if(str[k]=='"') obj.v[key]=node(get_str(k));
else if(str[k]=='{')
{
obj.v[key]=work_obj(k);
if(k+1<str.length()&&str[k+1]==',') k++;
}
else k++;
}
//cout<<str[k+1]<<endl;
}
node work_obj(int &k)
{
node obj;
obj.type=2;
while(str[k]!='{') k++;
while(str[k]!='}')
{
if(str[k]=='"')
{
work_kv(obj,k);
}
else k++;
}
return obj;
}
void query(node obj,vector<string> g)
{
node o;
string p;
for(int j=0;j<g.size();j++)
{
string i=g[j];
p=i;
//cout<<p<<endl;
if(obj.v.find(p)==obj.v.end())
{
cout<<"NOTEXIST"<<endl;
return;
}
o=obj.v[p];
obj=o;
}
if(obj.type==1) cout<<"STRING "<<obj.t<<endl;
else cout<<"OBJECT"<<endl;
}
int main()
{
cin>>n>>m;
string tem;
getchar();
for(int i=0;i<n;i++)
{
getline(cin,tem);
str+=tem;
}
//pro();
int k=0;
node obj=work_obj(k);
for(int i=0;i<m;i++)
{
int j=0;
string y;
vector<string>g;
getline(cin,y);
for(int u=0;u<y.length();u++)
{
j=u;
while(j<y.length()&&y[j]!='.') j++;
//cout<<y.substr(u,j-u)<<endl;
g.push_back(y.substr(u,j-u));
u=j;
}
query(obj,g);
}
return 0;
}
python
from sys import stdin
n,m=stdin.readline().split(' ')
n=int(n)
m=int(m)
str=''
while n:
n-=1
str+=stdin.readline()
obj=eval(str)
def query(o,s):
x=o
for i in range(len(s)-1):
t=s[i]
if t not in x.keys():
print("NOTEXIST")
return
elif type(x[t]) is dict:
x=x[t]
else:
print("NOTEXIST")
return
t = s[-1]
if t not in x.keys():
print("NOTEXIST")
elif type(x[t]) is dict:
print("OBJECT")
else:
print("STRING " + x[t])
while m:
m-=1
s=stdin.readline()
s=s.strip('\n')
s=s.split('.')
query(obj,s)