#include <bits/stdc++.h>
using namespace std;
string S;
int K;
int Sum[3000001];
int Kth(int k) {
  int Current = 0, P = 0;
  for (int i = 21; i >= 0; i--)
    if (P + (1 << i) <= K && Current + Sum[P + (1 << i)] <= k)
      Current += Sum[P += 1 << i];
  return P;
}
void Delete(int X) {
  while (X <= K) {
    Sum[X]--;
    X += X & -X;
  }
}
int main() {
  char c;
  while (c = getchar(), c == 'A' || c == 'C' || c == 'T' || c == 'G') S += c;
  int N;
  scanf("%d%d", &K, &N);
  static int L[5000], R[5000];
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &L[i], &R[i]);
    L[i]--;
    R[i]--;
  }
  for (int i = 0; i <= K; i++) Sum[i] = i & -i;
  static int Pre[3000000];
  for (int i = 0; i < K; i++) Pre[i] = -1;
  for (int i = N - 1, Total = K; i >= 0; i--) {
    for (int j = L[i] + 1; j <= R[i] && R[i] + 1 < Total; j += 2) {
      int T = Kth(R[i] + 1);
      Pre[T] = Kth(j);
      Delete(T + 1);
      Total--;
    }
    for (int j = L[i]; j <= R[i] && R[i] + 1 < Total; j += 2) {
      int T = Kth(R[i] + 1);
      Pre[T] = Kth(j);
      Delete(T + 1);
      Total--;
    }
  }
  static char Ans[3000000];
  for (int i = 0, j = 0; i < K; i++)
    if (Pre[i] == -1)
      putchar(Ans[i] = S[j++]);
    else
      putchar(Ans[i] = Ans[Pre[i]]);
  putchar('\n');
  return 0;
}
