#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 10;
int B[N];
void add(int u, int d) {
  for (; u < N; u += u & -u) B[u] += d;
}
int get(int u, int ans = 0) {
  for (; u > 0; u -= u & -u) ans += B[u];
  return ans;
}
const int T = 1 << 21;
int pos(int f) {
  if (get(N - 1) < f) return N;
  int id = 0;
  for (int j = T; j > 0; j >>= 1) {
    if (id + j < N) {
      if (B[id + j] < f) {
        f -= B[id + j];
        id += j;
      }
    }
  }
  return id + 1;
}
char s[N];
char t[N];
int seg[5050][2];
int m;
int k;
using pii = pair<int, int>;
pii v[N];
int vn;
void recover(int L, int R, int layer) {
  if (R >= get(N - 1)) return;
  int len = R - L + 1;
  int even = len / 2;
  len = min(len, get(N - 1) - R);
  for (int i = 1; i <= len && R + i <= k; i++) {
    v[vn++] = {pos(R + 1),
               i <= even ? pos(L + i * 2 - 1) : pos(L + (i - even - 1) * 2)};
    add(pos(R + 1), -1);
  }
}
int main() {
  scanf("%s", s + 1);
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    add(i, 1);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", seg[i] + 0, seg[i] + 1);
  }
  for (int i = m - 1; i >= 0; i--) {
    recover(seg[i][0], seg[i][1], i);
  }
  for (int i = get(N - 1); i >= 1; i--) {
    t[pos(i)] = s[i];
  }
  for (int i = vn; i--;) {
    t[v[i].first] = t[v[i].second];
  }
  printf("%s\n", t + 1);
  return 0;
}
