#include <bits/stdc++.h>
using namespace std;
const int N = 3E6 + 5;
const int M = 3E6 + 5;
struct map {
  int l, r;
} Q[M];
int n, m, k, len, tr[N * 4], u, x, P[N], tot;
char s[N], ans[N], ch;
void add(int p, int l, int r, int x) {
  if (x < l || x > r) return;
  tr[p]++;
  if (l == r) return;
  int mid = (l + r) / 2;
  add(p * 2, l, mid, x);
  add(p * 2 + 1, mid + 1, r, x);
}
int get(int x) {
  for (int p = 1, l = 1, r = k;;) {
    if (l == r) return x == 1 && !tr[p] ? l : k + 1;
    int mid = (l + r) / 2;
    if (mid - l + 1 - tr[p * 2] < x) {
      x -= mid - l + 1 - tr[p * 2];
      l = mid + 1;
      p = p * 2 + 1;
    } else
      r = mid, p *= 2;
  }
}
int main() {
  while (ch = getchar(), ch != '\n' && tot < N) s[tot++] = ch;
  if (ch != '\n')
    while (ch = getchar(), ch != '\n')
      ;
  scanf("%d%d", &k, &n);
  for (int i = 1; i <= n; i++) scanf("%d%d", &Q[i].l, &Q[i].r);
  for (int i = n; i; i--) {
    len = Q[i].r - Q[i].l + 1;
    u = 1;
    for (int j = Q[i].l + 1; j <= Q[i].r && Q[i].r + u <= k; j += 2) {
      x = get(Q[i].r + 1);
      if (x > k) break;
      P[x] = get(j);
      u++;
      add(1, 1, k, x);
    }
    for (int j = Q[i].l; j <= Q[i].r && Q[i].r + u <= k; j += 2) {
      x = get(Q[i].r + 1);
      if (x > k) break;
      P[x] = get(j);
      u++;
      add(1, 1, k, x);
    }
  }
  u = 0;
  for (int i = 1; i <= k; i++) {
    if (!P[i])
      ans[i] = s[u++];
    else
      ans[i] = ans[P[i]];
    putchar(ans[i]);
  }
}
