Help me in solving MIME2 problem

My issue

my output is somehow exting execution when output first time becomes unknown and then execution is ending

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
int n,m;
cin>>n>>m;
int a;
string s[n],k[n];
for(a=0;a<n;a++){
  cin>>s[a]>>k[a];  
  }
 string o;
 for(a=0;a<m;a++){
   cin>>o;
   string l="unknown";
   stack<char>h;
  int x=o.size()-1;
  while(o[x]!='.'){
     h.push(o[x]);
     x--;
  }
  
   string y="";
  while(h.empty()==0){
      y=y+h.top();
      h.pop();
  }
  
  int p=0;
  
  for(a=0;a<n;a++){
      if(y==s[a]){cout<<k[a]<<endl;p=1;break;}
      else{p=0;}
  }
  if(p==0){cout<<l<<endl;}
  
  
  
 } 
return 0;

}

Problem Link: Internet Media Types Practice Coding Problem