#include <bits/stdc++.h>
const double pi = 3.141592653589793238462643383279;
namespace MyMinMax {
template <typename T>
inline T mn(const T x, const T y) {
  return x < y ? x : y;
}
template <typename T>
inline T mx(const T x, const T y) {
  return x > y ? x : y;
}
template <typename T>
inline void chmin(T &x, const T y) {
  (x > y) && (x = y);
}
template <typename T>
inline void chmax(T &x, const T y) {
  (x < y) && (x = y);
}
template <typename T, typename... Args>
inline T mx(const T x, const Args... args) {
  return mx(x, mx(args...));
}
template <typename T, typename... Args>
inline T mn(const T x, const Args... args) {
  return mn(x, mn(args...));
}
}  // namespace MyMinMax
using namespace MyMinMax;
namespace IO {
const int DPAIRSIZ = 1 << 18;
char BB[DPAIRSIZ], *SS = BB, *TT = BB;
template <typename T = int>
inline T read() {
  T x = 0;
  int fu = 1;
  char c =
      (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
           ? EOF
           : *SS++);
  while (c > 57 || c < 48) {
    if (c == 45) fu = -1;
    c = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
             ? EOF
             : *SS++);
  }
  while (c <= 57 && c >= 48) {
    x = x * 10 + c - 48;
    c = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
             ? EOF
             : *SS++);
  }
  x *= fu;
  return x;
}
template <typename T>
inline void read(T &x) {
  x = 0;
  int fu = 1;
  char c =
      (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
           ? EOF
           : *SS++);
  while (c > 57 || c < 48) {
    if (c == 45) fu = -1;
    c = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
             ? EOF
             : *SS++);
  }
  while (c <= 57 && c >= 48) {
    x = x * 10 + c - 48;
    c = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
             ? EOF
             : *SS++);
  }
  x *= fu;
}
template <typename T>
inline void read(T *bg, T *ed) {
  while (bg != ed) read(*bg++);
}
inline void read(char &ch) {
  ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
            ? EOF
            : *SS++);
  while (ch <= 32)
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
}
inline void read(char *s) {
  char ch =
      (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
           ? EOF
           : *SS++);
  while (ch <= 32)
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  while (ch > 32)
    *s++ = ch,
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  *s = '\0';
}
inline void sread(char *s) {
  char ch =
      (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
           ? EOF
           : *SS++);
  while (ch < 32)
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  while (ch >= 32)
    *s++ = ch,
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  *s = '\0';
}
inline void pread(char *&s) {
  char ch =
      (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
           ? EOF
           : *SS++);
  while (ch <= 32)
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  while (ch > 32)
    *s++ = ch,
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  *s = '\0';
}
inline void spread(char *&s) {
  char ch =
      (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
           ? EOF
           : *SS++);
  while (ch < 32)
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  while (ch >= 32)
    *s++ = ch,
    ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, DPAIRSIZ, stdin), SS == TT)
              ? EOF
              : *SS++);
  *s = '\0';
}
template <typename T, typename... Args>
inline void read(T &x, Args &...args) {
  read(x);
  read(args...);
}
char out[DPAIRSIZ], *Out = out;
inline void putcha(char x) {
  *Out++ = x;
  if (Out - out >= (DPAIRSIZ)) fwrite(out, 1, Out - out, stdout), Out = out;
}
template <typename T>
inline void fprint(T x) {
  if (x < 0) putcha(45), x = -x;
  if (x > 9) fprint(x / 10);
  putcha(x % 10 + 48);
}
template <typename T>
inline void print(T x) {
  fprint(x);
  putcha(10);
}
inline void print(char *ch) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
}
inline void put(char *ch) {
  while (*ch != '\0') putcha(*(ch++));
}
inline void print(const char *ch) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
}
inline void put(const char *ch) {
  while (*ch != '\0') putcha(*(ch++));
}
template <typename T, typename... Args>
inline void print(T x, Args... args) {
  fprint(x);
  putcha(32);
  print(args...);
}
template <typename... Args>
inline void print(const char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(32);
  print(args...);
}
template <typename... Args>
inline void print(char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(32);
  print(args...);
}
template <typename T, typename... Args>
inline void printl(T x, Args... args) {
  fprint(x);
  putcha(10);
  print(args...);
}
template <typename... Args>
inline void printl(const char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
  print(args...);
}
template <typename... Args>
inline void printl(char *ch, Args... args) {
  while (*ch != '\0') putcha(*(ch++));
  putcha(10);
  print(args...);
}
template <typename T>
inline void sprint(T x) {
  fprint(x);
  putcha(32);
}
template <typename T, typename... Args>
inline void sprint(T x, Args... args) {
  fprint(x);
  putcha(32);
  sprint(args...);
}
template <typename T>
inline void sprint(T *bg, T *ed) {
  while (bg != ed) sprint(*bg++);
}
template <typename T>
inline void print(T *bg, T *ed) {
  while (bg != ed) sprint(*bg++);
  putcha(10);
}
template <typename T>
inline void printl(T *bg, T *ed) {
  while (bg != ed) print(*bg++);
}
class AutoFlush {
 public:
  ~AutoFlush() { fwrite(out, 1, Out - out, stdout); }
} __AutoFlush;
}  // namespace IO
using namespace IO;
int n, m, a[1000005];
long long s[1000005], p;
long long buf[1000005 << 4 | 5], *v[1000005 << 2],
    *ed = buf + sizeof(buf) / sizeof(long long),
    *fed = buf + (sizeof(buf) / sizeof(long long) >> 1);
inline long long *alloc(int siz) { return ed -= siz; }
inline long long *falloc(int siz) { return fed -= siz; }
const int alpha = 16;
inline void merge(long long *c, long long *x, long long *y, const long long w,
                  const int l1, const int l2) {
  for (int i = 0, j = 0; i < l1; ++i) {
    for (j == l2 && --j; j < l2; ++j) {
      if (w - p * i + x[i + 1] - 1 < y[j]) {
        if (j) --j;
        break;
      }
      c[i + j] = mx(x[i], y[j] - w + p * i);
    }
  }
}
void build(const int rt, const int l, const int r) {
  if (r - l + 1 <= alpha)
    v[rt] = falloc(r - l + 3);
  else
    v[rt] = alloc(r - l + 3);
  v[rt][0] = -0x3f3f3f3f3f3f3f3fll;
  v[rt][r - l + 2] = 0x3f3f3f3f3f3f3f3fll;
  if (l == r) return v[rt][1] = p - a[l], void();
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  merge(v[rt], v[rt << 1], v[rt << 1 | 1], s[mid] - s[l - 1], mid - l + 3,
        r - mid + 2);
}
inline void ADD(long long &x, const int y) {
  if ((x += y) >= p) x -= p;
}
int x, y;
long long z;
void query(const int rt, const int l, const int r) {
  if (x <= l && r <= y) {
    if (r - l + 1 <= alpha)
      for (int i = (l); i <= (r); ++i) ADD(z, a[i]);
    else
      z += s[r] - s[l - 1] -
           p * (std ::upper_bound(v[rt], v[rt] + r - l + 3, z) - 1 - v[rt]);
    return;
  }
  int mid = (l + r) >> 1;
  if (x > mid) return query(rt << 1 | 1, mid + 1, r);
  query(rt << 1, l, mid);
  if (y > mid) query(rt << 1 | 1, mid + 1, r);
}
int main() {
  read(n, m, p);
  read(a + 1, a + n + 1);
  for (int i = (1); i <= (n); ++i) s[i] = s[i - 1] + a[i];
  build(1, 1, n);
  while (m--) {
    read(x, y);
    z = 0;
    query(1, 1, n);
    print(z);
  }
}
