#include <bits/stdc++.h>
using namespace std;
string ss;
int f[30];
int n, m;
int main() {
  cin >> n >> m;
  cin >> ss;
  for (int i = 0; i < 30; i++) f[i] = i;
  char a[2], b[2];
  for (int i = 1; i <= m; i++) {
    scanf("%s%s", a, b);
    for (int j = 0; j < 27; j++) {
      if (f[j] == b[0] - 'a') {
        f[j] = a[0] - 'a';
      } else if (f[j] == a[0] - 'a') {
        f[j] = b[0] - 'a';
      }
    }
  }
  for (int i = 0; i < n; i++) printf("%c", f[ss[i] - 'a'] + 'a');
  return 0;
}
