#include <bits/stdc++.h>
std::vector<long long> Tree[1000005 * 4];
int n, m, mod, a[1000005];
long long sum[1000005 * 4], ans;
int read() {
  char c = getchar();
  int ans = 0;
  bool flag = 1;
  while (c < '0' || c > '9') flag &= (c != '-'), c = getchar();
  while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
  return flag ? ans : -ans;
}
void Write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x < 10)
    putchar(x ^ 48);
  else
    Write(x / 10), putchar((x % 10) ^ 48);
  return;
}
long long min(long long u, long long v) { return u < v ? u : v; }
long long max(long long u, long long v) { return u > v ? u : v; }
void build_tree(int L, int R, int rt) {
  if (L == R)
    return sum[rt] = a[L], Tree[rt].push_back(-100000000000000000ll),
           Tree[rt].push_back(mod - a[L]);
  build_tree(L, (L + R) / 2, rt << 1),
      build_tree((L + R) / 2 + 1, R, rt << 1 | 1);
  Tree[rt] = std::vector<long long>(R - L + 2, 100000000000000000ll);
  sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
  for (register int i = 0, j = 0; i < Tree[rt << 1].size(); i++) {
    long long xl = Tree[rt << 1][i],
              xr = (i + 1 < Tree[rt << 1].size() ? Tree[rt << 1][i + 1] - 1
                                                 : 100000000000000000ll);
    long long yl = xl + sum[rt << 1] - (mod + 0ll) * i,
              yr = xr + sum[rt << 1] - (mod + 0ll) * i;
    if (i) {
      while (j && Tree[rt << 1 | 1][j] > yl) j--;
      while (j < Tree[rt << 1 | 1].size() && Tree[rt << 1 | 1][j] <= yl) j++;
      j--;
    }
    while (j < Tree[rt << 1 | 1].size() && Tree[rt << 1 | 1][j] <= yr)
      Tree[rt][i + j] =
          min(Tree[rt][i + j],
              max(xl, Tree[rt << 1 | 1][j] - sum[rt << 1] + (i + 0ll) * mod)),
                   j++;
  }
  return (void)(Tree[rt][0] = -100000000000000000ll);
}
void query(int L, int R, int l, int r, int rt) {
  if (l <= L && R <= r)
    return (void)(ans = ans + sum[rt] -
                        (mod + 0ll) * (std::upper_bound(Tree[rt].begin(),
                                                        Tree[rt].end(), ans) -
                                       Tree[rt].begin() - 1));
  if ((L + R) / 2 >= l) query(L, (L + R) / 2, l, r, rt << 1);
  if ((L + R) / 2 < r) query((L + R) / 2 + 1, R, l, r, rt << 1 | 1);
  return;
}
int main() {
  n = read(), m = read(), mod = read();
  for (register int i = 1; i <= n; i++) a[i] = read();
  build_tree(1, n, 1);
  for (register int _ = 1, x, y; _ <= m; _++)
    x = read(), y = read(), ans = 0, query(1, n, x, y, 1), Write(ans),
    putchar('\n');
  return 0;
}
