#include <bits/stdc++.h>
using namespace std;
int size[30000001], v[3000001];
int n, m;
char str[3000001], ans[3000001];
int l[6001], r[6001];
inline void Build_tree(int x, int l, int r) {
  size[x] = r - l + 1;
  if (l >= r) return;
  int mid = (l + r) >> 1;
  Build_tree(x << 1, l, mid), Build_tree(x << 1 | 1, mid + 1, r);
}
inline int Query(int x, int l, int r, int k) {
  if (l == r) return l;
  int mid = (l + r) >> 1;
  if (k <= size[x << 1])
    return Query(x << 1, l, mid, k);
  else
    return Query(x << 1 | 1, mid + 1, r, k - size[x << 1]);
}
inline void Del(int x, int l, int r, int p) {
  if (p < l || p > r) return;
  --size[x];
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (p <= mid)
    Del(x << 1, l, mid, p);
  else
    Del(x << 1 | 1, mid + 1, r, p);
}
int main() {
  scanf("%s", str + 1);
  scanf("%d %d", &m, &n);
  for (int i = 1; i <= n; i++) scanf("%d %d", &l[i], &r[i]);
  Build_tree(1, 1, m);
  for (int i = n; i >= 1; i--)
    if (r[i] < size[1]) {
      int tmp = l[i] < r[i] ? l[i] + 1 : l[i];
      for (int j = 1; j <= r[i] - l[i] + 1 && r[i] < size[1]; j++) {
        int get = Query(1, 1, m, r[i] + 1);
        Del(1, 1, m, get), v[get] = Query(1, 1, m, tmp), tmp += 2;
        if (tmp > r[i]) tmp = l[i];
      }
    }
  int top = 0;
  for (int i = 1; i <= m; i++)
    if (!v[i])
      ans[i] = str[++top];
    else
      ans[i] = ans[v[i]];
  for (int i = 1; i <= m; i++) printf("%c", ans[i]);
  printf("\n");
  return 0;
}
