//6 1
//police
//p m
//11 6
//abacabadaba
//a b
//b c
//a d
//e g
//f a
//b b
#include<bits/stdc++.h>
int st[26][200000]={},tempst[200000],top[26]={};
char a[200001];
int main()
{
int n,m,i,v,j,top1,top2,v2;
char b,c;
scanf("%d%d",&n,&m);
fflush(stdin);
gets(a);
//scanf("%s",a);
for(i=0;i<n;i++)
{
//scanf("%c",&a[i]);
if(a[i]==' ') continue;
v=a[i]-'a';
st[v][top[v]]=i;
top[v]++;
}
for(i=0;i<m;i++)
{
fflush(stdin);
scanf("%c %c",&b,&c);
//printf("%c %c\n",b,c);
v=b-'a';
for(j=0;j<top[v];j++) a[st[v][j]]=c;
v=c-'a';
for(j=0;j<top[v];j++) a[st[v][j]]=b;
v=b-'a';
top1=top[v];
for(j=0;j<top1;j++) tempst[j]=st[v][j];
v2=c-'a';
top2=top[v2];
for(j=0;j<top2;j++) st[v][j]=st[v2][j];
for(j=0;j<top1;j++) st[v2][j]=tempst[j];
top[v]=top2;
top[v2]=top1;
}
printf("%s",a);
return 0;
}
Ly82IDEKLy9wb2xpY2UKLy9wIG0KCi8vMTEgNgovL2FiYWNhYmFkYWJhCi8vYSBiCi8vYiBjCi8vYSBkCi8vZSBnCi8vZiBhCi8vYiBiCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CmludCBzdFsyNl1bMjAwMDAwXT17fSx0ZW1wc3RbMjAwMDAwXSx0b3BbMjZdPXt9OwpjaGFyIGFbMjAwMDAxXTsKaW50IG1haW4oKQp7CiAgICBpbnQgbixtLGksdixqLHRvcDEsdG9wMix2MjsKICAgIGNoYXIgYixjOwogICAgc2NhbmYoIiVkJWQiLCZuLCZtKTsKICAgIGZmbHVzaChzdGRpbik7CiAgICBnZXRzKGEpOwogICAgLy9zY2FuZigiJXMiLGEpOwogICAgZm9yKGk9MDtpPG47aSsrKQogICAgewogICAgICAgIC8vc2NhbmYoIiVjIiwmYVtpXSk7CiAgICAgICAgaWYoYVtpXT09JyAnKSBjb250aW51ZTsKICAg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