#include <bits/stdc++.h>
const int mn = 10100, mm = 5010000;
char st[mm], ans[mm];
int f[mm], s[mm], L[mn], R[mn];
int n, m, K, i, j, d, len, now;
void del(int p) {
  for (; p <= m; p += p & (-p)) --s[p];
}
int query(int v) {
  int i = 1, l = m >> 1;
  for (; l; l >>= 1)
    if (s[i + l - 1] < v) v -= s[i + l - 1], i += l;
  return i;
}
int main() {
  scanf("%s", st + 1);
  scanf("%d", &K);
  for (m = 1; m < K; m <<= 1)
    ;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) scanf("%d%d", L + i, R + i);
  for (i = 1; i <= m; ++i) s[i] = i & (-i);
  for (i = n; i >= 1; --i) {
    if (R[i] >= s[m]) continue;
    len = R[i] - L[i] + 1, now = L[i] + 1;
    for (j = 1; j <= len; ++j) {
      if (R[i] >= s[m]) break;
      if (now > R[i]) now = L[i];
      d = query(R[i] + 1), del(d);
      f[d] = query(now);
      now += 2;
    }
  }
  j = 1;
  for (i = 1; i <= K; ++i) ans[i] = f[i] ? ans[f[i]] : st[j++];
  puts(ans + 1);
  return 0;
}
