/*
TASK:school
LANG:C++
*/
#include<iostream>
#include<string>
using namespace std;

int main()
{
long brg=0,brb=0,bru=0,i,j,l,l1,n,m,k;
int s[1001],mom,moso,momiche[1001],mo[1001],t[1001],t1[1001],min=0,min1=0;
char p[1001];
cin>>n>>m>>k;
bru=m+n;
l=1;
l1=1;
for(i=1;i<=bru;i++)
{
cin>>t[i]>>p[i];
if(p[i]=='G') {brg++; momiche[l]=t[i]; l++;}
else {brb++; mo[l1]=t[i]; l1++;}
}    

for(i=1;i<=brb;i++)
{

for(j=1;j<=brb;j++)
{
if(mo[i]<mo[j]) {mom=mo[i]; mo[i]=mo[j]; mo[j]=mom;}                   
}                   
}


for(i=1;i<=brg;i++)
{

for(j=1;j<=brg;j++)
{
if(momiche[i]<momiche[j]) {moso=momiche[i]; momiche[i]=momiche[j]; momiche[j]=moso;}                   
}                   
}

int g=1;
for(j=brg;j>=1;j--)
{
s[g]=momiche[j];
g++;
}

int g1=1;
for(j=brb;j>=1;j--)
{
t1[g1]=mo[j];
g1++;
}

if(brb>=k && brg>=k)
cout<<t1[k]<<" "<<s[k]<<endl;

if(brb<k && brg>=k)
{
         if(brb!=1) cout<<t1[brb]<<" "<<s[k+(k-brb)]<<endl;
         else cout<<t1[brb]<<" "<<s[k+1]<<endl;
}

if(brb>=k && brg<k)
cout<<t1[k+(k-brg)]<<" "<<s[brg]<<endl;

if(brg<k && brb<k)
cout<<t1[brb]<<" "<<s[brg]<<endl;
system("pause");
return 0;
}
