#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)100000000 * (long long)10000000;
long long n, m, p, q;
long long a[1000005];
long long read() {
  long long x;
  long long f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
  return x;
}
void rd() {
  n = read();
  q = read();
  p = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
}
struct node {
  long long l, r, n;
  long long s;
  vector<long long> c;
} c[1000005 << 2];
void merge(long long i) {
  long long y = 1;
  for (long long x = 0; x <= c[(i << 1)].n; x++) {
    if (y != 0) y--;
    for (; y <= c[((i << 1) | 1)].n; y++) {
      long long t = c[((i << 1) | 1)].c[y] + x * p - c[(i << 1)].s;
      long long w = c[(i << 1)].c[x + 1] - 1 - x * p + c[(i << 1)].s;
      if (w < c[((i << 1) | 1)].c[y]) {
        if (y != 0) y--;
        break;
      }
      c[i].c[x + y] = min(c[i].c[x + y], max(c[(i << 1)].c[x], t));
    }
  }
}
void build(long long i, long long l, long long r) {
  long long mid = (l + r) >> 1;
  c[i].l = l;
  c[i].r = r;
  c[i].n = r - l + 1;
  for (long long j = 1; j <= c[i].n + 2; j++) {
    c[i].c.push_back(INF);
  }
  c[i].c[0] = -INF;
  if (l == r) {
    c[i].s = a[l];
    c[i].c[0] = (-INF);
    c[i].c[1] = p - a[l];
    c[i].c[2] = INF;
    return;
  }
  build((i << 1), l, mid);
  build(((i << 1) | 1), mid + 1, r);
  c[i].s = c[(i << 1)].s + c[((i << 1) | 1)].s;
  merge(i);
  for (long long j = 0; j <= c[i].n; j++)
    if (c[i].c[j] != INF && c[i].c[j] == c[i].c[j + 1]) exit(1);
}
long long ans = 0;
void query(long long i, long long l, long long r) {
  if (l > c[i].r || r < c[i].l) return;
  if (l <= c[i].l && c[i].r <= r) {
    long long lb = 0, rb = c[i].n + 1;
    while (lb + 3 < rb) {
      long long x = (lb + rb) >> 1;
      if (c[i].c[x] <= ans)
        lb = x;
      else
        rb = x;
    }
    for (long long j = rb; j >= lb; j--) {
      if (c[i].c[j] <= ans) {
        ans = ans + c[i].s - j * p;
        return;
      }
    }
    return;
  }
  query((i << 1), l, r);
  query(((i << 1) | 1), l, r);
}
signed main() {
  rd();
  build(1, 1, n);
  while (q--) {
    long long l, r;
    l = read();
    r = read();
    ans = 0;
    query(1, l, r);
    printf("%lld\n", ans);
  }
  return 0;
}
