#include <bits/stdc++.h>
using namespace std;
vector<int> characters[123];
int main() {
  int n, m, i, j;
  scanf("%d %d%*c", &n, &m);
  char str[n + 1], change_str[4];
  for (i = 0; i < n; i++) {
    scanf("%c", &str[i]);
    characters[str[i]].push_back(i);
  }
  str[n] = '\0';
  scanf("%*c");
  for (i = 0; i < m; i++) {
    gets(change_str);
    if (!(characters[change_str[0]].size())) {
      characters[change_str[0]] = characters[change_str[2]];
      characters[change_str[2]].clear();
    } else if (!(characters[change_str[2]].size())) {
      characters[change_str[2]] = characters[change_str[0]];
      characters[change_str[0]].clear();
    } else {
      swap(characters[change_str[0]], characters[change_str[2]]);
    }
  }
  for (i = 97; i < 123; i++) {
    for (j = 0; j < characters[i].size(); j++) str[characters[i][j]] = i;
  }
  str[n] = '\0';
  puts(str);
}
