#include <bits/stdc++.h>
using namespace std;
char s[4200005];
int n, k, i, j, R, L, t, mxn, rt[4200005], c[4200005], pre[4200005], l[5005],
    r[5005];
int lowbit(int x) { return x & -x; }
void add(int x, int d) {
  for (int i = x; i <= mxn; i += lowbit(i)) c[i] += d;
}
int find(int x, int k) {
  int t = x - (lowbit(x) >> 1);
  while (k > c[t] && t < x) k -= c[t], t += max((lowbit(t) >> 1), 1);
  if (k == 1 && t == x) return x;
  return find(t, k);
}
int main() {
  scanf("%s", s + 1);
  scanf("%d%d", &k, &n);
  mxn = 1;
  while (mxn < k) mxn <<= 1;
  for (i = 1; i <= n; i++) scanf("%d%d", &l[i], &r[i]);
  memset(c, 0, sizeof(c));
  for (i = 1; i <= k; i++) add(i, 1), pre[i] = i;
  for (i = n; i; i--)
    if (r[i] < k) {
      L = r[i] + 1;
      R = min(r[i] + r[i] - l[i] + 1, k);
      for (j = 1; j <= R - L + 1; j++) {
        if (L > c[mxn]) break;
        t = find(mxn, L);
        if (j <= (r[i] - l[i] + 1) / 2)
          pre[t] = find(mxn, l[i] - 1 + 2 * j);
        else
          pre[t] = find(mxn, l[i] - 2 + 2 * (j - (r[i] - l[i] + 1) / 2));
        add(t, -1);
      }
    }
  int t;
  memset(rt, 0, sizeof(rt));
  for (i = 1; i <= c[mxn]; i++) pre[t = find(mxn, i)] = i, rt[t] = 1;
  for (i = 1; i <= k; i++) {
    if (!rt[i]) pre[i] = pre[pre[i]];
    printf("%c", s[pre[i]]);
  }
}
