#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char c = getchar();
  long long sum = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) sum = sum * 10 + c - '0';
  return (f == -1) ? -sum : sum;
}
inline void wr(long long x) {
  if (x < 0) {
    putchar('-');
    wr(-x);
  } else {
    if (x >= 10) wr(x / 10);
    putchar('0' + x % 10);
  }
}
inline void wrn(long long x) {
  wr(x);
  putchar('\n');
}
inline void wri(long long x) {
  wr(x);
  putchar(' ');
}
inline void wrn(long long x, long long y) {
  wri(x);
  wrn(y);
}
long long n, m, tot, p, a[1000055], l, r, z[1000055];
struct xx {
  long long l, r;
  long long sum;
} t[1000055 * 4];
vector<long long> v[1000055 * 4];
void upd(long long x) {
  t[x].sum = t[x * 2].sum + t[x * 2 + 1].sum;
  long long t1 = x * 2, t2 = x * 2 + 1, l2 = 0, r1 = v[t1].size() - 1,
            r2 = v[t2].size() - 1;
  while (v[t1][0] + t[t1].sum - 1 >= v[t2][l2] && l2 <= r2)
    v[x].push_back(v[t2][l2] - t[t1].sum), l2++;
  for (long long i = (0); i <= (r1); i++) {
    if (l2 == 0)
      v[x].push_back(v[t1][i]);
    else
      v[x].push_back(max(v[t1][i], v[t2][l2 - 1] + (i + 1) * p - t[t1].sum));
    while (v[t1][i + 1] - 1 + t[t1].sum - (i + 1) * p >= v[t2][l2] && l2 <= r2)
      v[x].push_back(v[t2][l2] - t[t1].sum + (i + 1) * p), l2++;
  }
  while (l2 <= r2) v[x].push_back(v[t2][l2] - t[t1].sum + (r1 + 1) * p), l2++;
  if (v[x].size() != t[x].r - t[x].l + 1) exit(0);
  for (long long i = (1); i < (v[x].size()); i++)
    if (v[x][i] - v[x][i - 1] < p) {
      for (long long i = (0); i < (v[t1].size()); i++) wri(v[t1][i]);
      putchar('\n');
      for (long long i = (0); i < (v[t2].size()); i++) wri(v[t2][i]);
      putchar('\n');
      for (long long i = (0); i < (v[x].size()); i++) wri(v[x][i]);
      putchar('\n');
      exit(0);
    }
}
void build(long long x, long long l, long long r) {
  t[x].l = l;
  t[x].r = r;
  if (l == r) {
    v[x].push_back(p - a[l]);
    t[x].sum = a[l];
    return;
  }
  long long mid = (l + r) >> 1;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  upd(x);
}
void ge(long long x, long long l, long long r) {
  if (t[x].l == l && t[x].r == r) {
    z[++tot] = x;
    return;
  }
  long long mid = (t[x].l + t[x].r) >> 1;
  if (r <= mid)
    ge(x * 2, l, r);
  else if (l > mid)
    ge(x * 2 + 1, l, r);
  else
    ge(x * 2, l, mid), ge(x * 2 + 1, mid + 1, r);
}
void solve(long long l, long long r) {
  tot = 0;
  ge(1, l, r);
  long long ans = 0;
  for (long long i = (1); i <= (tot); i++)
    ans = ans + t[z[i]].sum -
          p * (upper_bound(v[z[i]].begin(), v[z[i]].end(), ans) -
               v[z[i]].begin());
  wrn(ans);
}
signed main() {
  n = read();
  m = read();
  p = read();
  for (long long i = (1); i <= (n); i++) a[i] = read();
  build(1, 1, n);
  for (long long i = (1); i <= (m); i++) {
    l = read();
    r = read();
    solve(l, r);
  }
}
