#include <bits/stdc++.h>
using namespace std;
struct question {
  int x, y;
};
struct question q[5010];
int n, m, l, l1;
int c[3000010], p[3000010];
char a[3000010], ans[3000010];
void change(int i, int x) {
  while (i <= n) {
    c[i] += x;
    i += i & (-i);
  }
}
int query(int i) {
  int j, s = 0, ret = 0;
  for (j = 21; j >= 0; j--)
    if (ret + (1 << j) <= n && s + c[ret + (1 << j)] < i) {
      s += c[ret + (1 << j)];
      ret += (1 << j);
    }
  return ret + 1;
}
int main() {
  int i, j, last, x, k;
  scanf("%s", a + 1);
  l = strlen(a + 1);
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) scanf("%d%d", &q[i].x, &q[i].y);
  for (i = 1; i <= n; i++) c[i] = i & (-i);
  last = n;
  for (i = m; i >= 1; i--) {
    for (j = q[i].x + 1, k = q[i].y + 1; j <= q[i].y && k <= last;
         j += 2, last--) {
      x = query(k);
      change(x, -1);
      p[x] = query(j);
    }
    for (j = q[i].x; j <= q[i].y && k <= last; j += 2, last--) {
      x = query(k);
      change(x, -1);
      p[x] = query(j);
    }
  }
  j = 1;
  for (i = 1; i <= n; i++)
    if (p[i])
      ans[i] = ans[p[i]];
    else if (j <= l)
      ans[i] = a[j++];
  for (i = 1; ans[i] != '\0'; i++) printf("%c", ans[i]);
  printf("\n");
  return 0;
}
