#include <bits/stdc++.h>
using std::min;
const int MAXL = 3000000 + 9, MAXM = 5000 + 9, M = 4194304;
int tr[M + M];
int ask(int k) {
  int i;
  for (i = 1; i < M;)
    if (k > tr[i + i]) {
      k -= tr[i + i];
      i += i + 1;
    } else
      i += i;
  return i - M;
}
void change(int u, int v) {
  for (u += M; u; u >>= 1) tr[u] += v;
}
int l[MAXM], r[MAXM];
int fa[MAXL];
char s[MAXL], ans[MAXL];
int main() {
  int k, m, i, j, t, tot;
  int ll, rr, ori;
  char *p;
  scanf("%s%d%d", s + 1, &k, &m);
  for (i = 1; i <= m; ++i) scanf("%d%d", l + i, r + i);
  for (i = 1; i <= k; ++i) change(i, 1);
  tot = k;
  for (i = m; i; --i) {
    if (r[i] + 1 > tot) continue;
    ll = r[i] - l[i] + 1;
    rr = min(tot, r[i] + ll);
    for (j = 1; j <= rr - r[i]; ++j) {
      m = ll >> 1;
      ori = j <= m ? l[i] - 1 + j + j : l[i] - 2 + 2 * (j - m);
      fa[t = ask(r[i] + 1)] = ask(ori);
      change(t, -1);
    }
    tot -= rr - r[i];
  }
  p = s;
  for (i = 1; i <= k; ++i) ans[i] = fa[i] ? ans[fa[i]] : *++p;
  puts(ans + 1);
  return 0;
}
