#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;

#define fore(i, l, r) for (auto i = (l) - ((l) > (r)); i != (r) - ((l) > (r)); i += 1 - 2 * ((l) > (r)))
#define ceil(n, k) (((n) + ((k) - 1)) / (k))
#define mod(n, k) (((n) + (k)) % (k))
#define all(x) begin(x), end(x)
#define sz(x) int(x.size())
#define pb push_back
#define f first
#define s second

using ld = long double;
using lli = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;

#ifdef LOCAL
  #include "../debug.h"
  const int N = 10;
#else
  #define debug(...)
  const int N = 1e6 + 5;
#endif

const int inf = numeric_limits<decltype(inf)>::max() / 2;

lli n, q, k;
lli a[N];
lli ps[N];

void testCase() {
  cin >> n >> q >> k;
  int i = 0;

  fore (j, 0, n) {
    cin >> a[j];
    if (a[j] <= k)
      i = j;
  }

  fore (i, 0, n) {
    if (i == 0) 
      ps[i] = a[i] - 1;
    if (i > 0)
      ps[i] += a[i] - a[i - 1] - 1;
    if (i < n - 1)
      ps[i] += a[i + 1] - a[i] - 1;
  }

  debug(ps);
  fore (i, 1, n)
    ps[i] += ps[i - 1];

  debug(ps);

  auto sum = [&] (int l, int r) {
    return ps[r] - (l == 0 ? 0 : ps[l - 1]);
  };

  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    r = min(r, i);
    debug(l, r, k, i);
    int ans = sum(l, r) + k - a[r];
    debug(ans);
    if (r < n - 1)
      ans -= a[r + 1] - a[r] - 1; 
    if (l > 0) {
      ans += a[l] - 1;
      ans -= a[l] - a[l - 1] - 1;
    }
    cout << ans << '\n';
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0), cout.tie(0);

  int tc = 1;
  // cin >> tc;

  while (tc--)
    testCase(); 

  return 0;
}
