#include <bits/stdc++.h>
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
char S[3000005];
int Tree[3000005];
int N, M, K;
int L[5005];
int R[5005];
int Ask(int X) {
  int Ans = 0;
  for (; X; X -= X & -X) {
    Ans += Tree[X];
  }
  return Ans;
}
void Add(int X, int Delta) {
  for (; X <= K; X += X & -X) {
    Tree[X] += Delta;
  }
}
int Father[3000005];
void Init() {
  gets(S + 1);
  N = strlen(S + 1);
  Get(K);
  Get(M);
  for (int i = 1; i <= M; i++) {
    Get(L[i]);
    Get(R[i]);
  }
  for (int i = 1; i <= K; i++) {
    Tree[i] = i & -i;
    Father[i] = i;
  }
}
int GetFa(int X) {
  if (Father[X] == X) return X;
  return Father[X] = GetFa(Father[X]);
}
int NowK[5005];
int Ori(int X) {
  int Ans = 0;
  for (int i = 21; i >= 0; i--) {
    if (Ans + (1 << i) <= K) {
      if (Tree[Ans + (1 << i)] < X) {
        X -= Tree[Ans + (1 << i)];
        Ans |= (1 << i);
      }
    }
  }
  Ans++;
  return Ans;
}
void Work() {
  NowK[M] = K;
  for (int i = M; i >= 1; i--) {
    int L0 = L[i];
    int R0 = R[i];
    int L1 = R0 + 1;
    int R1 = R0 + R0 + 1 - L0;
    if (L1 > NowK[i]) {
      NowK[i - 1] = NowK[i];
      continue;
    } else if (R1 >= NowK[i]) {
      int p = L1;
      for (int k = L0 + 1, Delete; k <= R0; k += 2, p++) {
        if (p <= NowK[i]) {
          Delete = Ori(L1);
          Father[GetFa(Delete)] = GetFa(Ori(k));
          Add(Delete, -1);
        } else
          break;
      }
      for (int k = L0, Delete; k <= R0; k += 2, p++) {
        if (p <= NowK[i]) {
          Delete = Ori(L1);
          Father[GetFa(Delete)] = GetFa(Ori(k));
          Add(Delete, -1);
        } else
          break;
      }
      NowK[i - 1] = R0;
      continue;
    } else {
      int p = L1;
      for (int k = L0 + 1, Delete; k <= R0; k += 2, p++) {
        Delete = Ori(L1);
        Father[GetFa(Delete)] = GetFa(Ori(k));
        Add(Delete, -1);
      }
      for (int k = L0, Delete; k <= R0; k += 2, p++) {
        Delete = Ori(L1);
        Father[GetFa(Delete)] = GetFa(Ori(k));
        Add(Delete, -1);
      }
      NowK[i - 1] = NowK[i] - (R0 - L0 + 1);
    }
  }
}
char Ans[3000005];
void Output() {
  for (int i = 1, j = 1, Pos; i <= K; i++) {
    Pos = GetFa(i);
    if (Pos == i) {
      Ans[i] = S[j];
      j++;
    } else {
      Ans[i] = Ans[Pos];
    }
    printf("%c", Ans[i]);
  }
  puts("");
}
int main() {
  Init();
  Work();
  Output();
  return 0;
}
