#include <bits/stdc++.h>
using namespace std;
map<char, char> s;
int main(int argc, const char* argv[]) {
  int m, n;
  cin >> n >> m;
  char c[n + 2];
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (char i = 'a'; i <= 'z'; i++) {
    s[i] = i;
  }
  for (int i = 0; i < m; i++) {
    char x, y;
    cin >> x >> y;
    for (char j = 'a'; j <= 'z'; j++) {
      if (s[j] == x)
        s[j] = y;
      else if (s[j] == y)
        s[j] = x;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s[c[i]];
  }
  return 0;
}
