#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
  if (first > second) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<ll, ll>;
using vi = vc<ll>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
  os << "{";
  for (auto e : v) os << e << ",";
  return os << "}";
}
template <class t>
void mkuni(vc<t>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
ll read() {
  ll i;
  cin >> i;
  return i;
}
const ll inf = LLONG_MAX / 3;
ll p;
struct N {
  vi x;
  ll s;
  void init(ll first) {
    x = {-inf, p - first, inf};
    s = first;
  }
  void mrg(const N& first, const N& second) {
    ll len = first.x.size() + second.x.size() - 4;
    x.push_back(-inf);
    ll c = 0, d = 0;
    for (ll num = ll(1); num < ll(len + 1); num++) {
      ll cur = x.back();
      while (c + d < num) {
        ll nx = min(first.x[c + 1] - cur,
                    second.x[d + 1] - (cur + first.s - c * p));
        cur += nx;
        if (first.x[c + 1] <= cur) c++;
        if (d) d--;
        while (second.x[d + 1] <= cur + first.s - c * p) d++;
      }
      x.push_back(cur);
    }
    x.push_back(inf);
    s = first.s + second.s;
  }
  ll get(ll v) {
    return v + s - (upper_bound(x.begin(), x.end(), v) - x.begin() - 1) * p;
  }
};
struct S {
  vc<N> buf;
  ll s;
  S(vi d) {
    s = 1;
    while (s < ll(d.size())) s *= 2;
    d.resize(s);
    buf.resize(s * 2);
    for (ll i = ll(0); i < ll(s); i++) buf[i + s].init(d[i]);
    for (ll i = ll(s) - 1; i >= 1; i--) buf[i].mrg(buf[i * 2], buf[i * 2 + 1]);
  }
  void get(ll second, ll e, ll& v, ll l, ll r, ll i) {
    if (e <= l || r <= second) return;
    if (second <= l && r <= e) {
      v = buf[i].get(v);
      return;
    }
    ll m = (l + r) / 2;
    get(second, e, v, l, m, i * 2);
    get(second, e, v, m, r, i * 2 + 1);
  }
  ll get(ll second, ll e) {
    ll v = 0;
    get(second, e, v, 0, s, 1);
    return v;
  }
};
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n = read(), m = read();
  p = read();
  vi first(n);
  for (ll i = ll(0); i < ll(n); i++) first[i] = read();
  S slv(first);
  for (ll _ = ll(0); _ < ll(m); _++) {
    ll l = read() - 1, r = read();
    cout << slv.get(l, r) << "\n";
  }
}
