#include <bits/stdc++.h>
using namespace std;
const int N = 3000005, M = 5005;
struct _two {
  int a, b;
  inline void Input(int A, int B) {
    a = A;
    b = B;
  }
} qu[M];
int k, n, m, tot;
int h[1 << 23], f[1 << 23], s[N], o[N];
void Ins(int x, int y) {
  while (x <= tot) {
    h[x] += y;
    x += ((x) & -(x));
  }
}
int Find(int x) {
  int cur = 0;
  for (int i = tot; i > 0; i >>= 1)
    if (h[cur + i] < x) {
      x -= h[cur + i];
      cur += i;
    }
  return cur + 1;
}
int main() {
  char c;
  m = 0;
  while (c = getchar(), c >= 'A' && c <= 'Z') s[++m] = c;
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &qu[i].a, &qu[i].b);
  for (tot = 1; tot < k; tot <<= 1)
    ;
  for (int i = 1; i <= tot; i++) h[i] = ((i) & -(i));
  for (int i = n; i >= 1; i--) {
    int l = qu[i].b - qu[i].a + 1;
    for (int j = qu[i].b + 1; j <= qu[i].b + l; j++) {
      if (qu[i].b >= h[tot]) break;
      int p = Find(qu[i].b + 1);
      Ins(p, -1);
      if (j <= (l >> 1) + qu[i].b) {
        f[p] = Find(qu[i].a + (j - qu[i].b) * 2 - 1);
      } else
        f[p] = Find(qu[i].a + (j - qu[i].b - (l >> 1) - 1) * 2);
    }
  }
  for (int i = tot - 1; i >= 1; i--) h[i + ((i) & -(i))] -= h[i];
  int num = 0;
  for (int i = 1; i <= k; i++)
    if (h[i])
      o[i] = s[++num];
    else
      o[i] = o[f[i]];
  for (int i = 1; i <= k; i++) putchar(o[i]);
  puts("");
  return 0;
}
