#include <bits/stdc++.h>
using namespace std;
const int MXN = 3000001, lgN = 23, MXQ = 5001;
int N, Q;
int l[MXQ], r[MXQ];
namespace Tarray {
int c[MXN];
void init() {
  for (int i = 1; i <= N; i++) c[i] = 0;
}
void ins(int x, int v) {
  for (; x <= N; x += ((x) & (-x))) c[x] += v;
}
int sum(int x) {
  int S = 0;
  for (; x > 0; x -= ((x) & (-x))) S += c[x];
  return S;
}
int kth(int k) {
  if (sum(N) < k) return 0;
  int x = 0;
  for (int i = lgN; i >= 0; i--)
    if (x + (1 << i) < N && c[x + (1 << i)] < k) x += 1 << i, k -= c[x];
  return x + 1;
}
}  // namespace Tarray
int f[MXN];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
char s[MXN], cmd[MXN];
void solve() {
  scanf("%s", s + 1);
  scanf("%d", &N);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) scanf("%d%d", l + i, r + i);
  for (int i = 1; i <= N; i++) f[i] = i;
  Tarray::init();
  for (int i = 1; i <= N; i++) Tarray::ins(i, 1);
  for (int i = Q; i >= 1; i--) {
    int len = r[i] - l[i] + 1;
    for (int k = 1; k <= len / 2; k++) {
      int p = r[i] + k, P = Tarray::kth(r[i] + 1);
      if (!P) break;
      Tarray::ins(P, -1);
      int pp = (l[i] - 1) + 2 * k, PP = Tarray::kth(pp);
      f[find(P)] = PP;
    }
    for (int k = 1; k <= len - len / 2; k++) {
      int p = r[i] + len / 2 + k, P = Tarray::kth(r[i] + 1);
      if (!P) break;
      Tarray::ins(P, -1);
      int pp = (l[i] - 2) + 2 * k, PP = Tarray::kth(pp);
      f[find(P)] = PP;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (i == find(i))
      cmd[i] = s[Tarray::sum(i)];
    else
      cmd[i] = cmd[find(i)];
  }
  for (int i = 1; i <= N; i++) printf("%c", cmd[i]);
  cout << endl;
}
int main() {
  solve();
  return 0;
}
