#include <bits/stdc++.h>
using std::cerr;
using std::endl;
inline int rd() {
  int a = 1, b = 0;
  char c = getchar();
  while (!isdigit(c)) a = c == '-' ? 0 : 1, c = getchar();
  while (isdigit(c)) b = b * 10 + c - '0', c = getchar();
  return a ? b : -b;
}
const int N = 1e6 + 233;
const long long INF = 1e18;
int n, m;
long long P;
long long val[N], sum[N];
std::vector<long long> seg[N * 4];
inline void pushup(int p, long long s) {
  seg[p].resize(seg[(p << 1)].size() + seg[((p << 1) | 1)].size() - 1);
  std::fill(seg[p].begin(), seg[p].end(), INF);
  for (int i = 0, j = 0; i < (int)seg[(p << 1)].size(); ++i) {
    long long dl = seg[(p << 1)][i],
              dr = (i + 1 == (int)seg[(p << 1)].size())
                       ? INF
                       : seg[(p << 1)][i + 1] - 1,
              vl = s + dl - P * i, vr = s + dr - P * i;
    if (j > 0) --j;
    while (j + 1 < (int)seg[((p << 1) | 1)].size() &&
           seg[((p << 1) | 1)][j + 1] < vl)
      ++j;
    while (j < (int)seg[((p << 1) | 1)].size() &&
           seg[((p << 1) | 1)][j] <= vr) {
      long long tmp = std::max(dl, seg[((p << 1) | 1)][j] - s + P * i);
      seg[p][i + j] = std::min(seg[p][i + j], tmp);
      ++j;
    }
  }
  seg[p][0] = -INF;
}
void build(int p, int L, int R) {
  if (L == R) {
    seg[p].push_back(-INF);
    seg[p].push_back(P - val[L]);
    return;
  }
  build((p << 1), L, ((L + R) >> 1));
  build(((p << 1) | 1), ((L + R) >> 1) + 1, R);
  pushup(p, sum[((L + R) >> 1)] - sum[L - 1]);
}
long long ans;
void query(int p, int l, int r, int L, int R) {
  if (l <= L && r >= R) {
    long long tmp = sum[R] - sum[L - 1];
    tmp -= (std::upper_bound(seg[p].begin(), seg[p].end(), ans) -
            seg[p].begin() - 1) *
           P;
    ans += tmp;
    return;
  }
  if (l <= ((L + R) >> 1)) query((p << 1), l, r, L, ((L + R) >> 1));
  if (r > ((L + R) >> 1)) query(((p << 1) | 1), l, r, ((L + R) >> 1) + 1, R);
}
int main() {
  n = rd(), m = rd(), P = rd();
  for (int i = 1; i <= n; ++i) sum[i] = (val[i] = rd()) + sum[i - 1];
  build(1, 1, n);
  while (m--) {
    int l = rd(), r = rd();
    ans = 0;
    query(1, l, r, 1, n);
    printf("%lld\n", ans);
  }
  return 0;
}
