#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000010, maxm = 10001;
int m, len, T;
char st[maxn], ans[maxn];
int Su[maxn], f[maxn];
int L[maxm], R[maxm];
void solve(int x, int y) {
  f[x] = y;
  --len;
  for (; x <= m; x += x & -x) Su[x]--;
}
int index(int x) {
  int i, j;
  --x;
  for (i = 1 << 23, j = 0; i; i >>= 1)
    if (j + i <= m && Su[j + i] <= x) j += i, x -= Su[j];
  return j + 1;
}
int main() {
  int i, j, k;
  scanf("%s", st + 1);
  scanf("%d", &m);
  scanf("%d", &T);
  for (i = 1; i <= T; ++i) scanf("%d %d\n", &L[i], &R[i]);
  for (i = 1; i <= m; ++i) Su[i] = i & -i;
  len = m;
  for (i = T; i; --i) {
    for (j = 1, k = L[i] + 1; j <= R[i] - L[i] + 1 && R[i] < len;
         solve(index(R[i] + 1), index(k)), ++j, k += 2)
      if (k > R[i]) k = L[i];
  }
  for (i = 1, j = 0; i <= m; ++i) {
    if (f[i])
      ans[i] = ans[f[i]];
    else
      ans[i] = st[++j];
    printf("%c", ans[i]);
  }
  return 0;
}
