#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int v[MAX5];

int f(int mid, int p, int k){
    multiset < int > s;
    for(int i = 0; i < mid; i++){
        s.insert(v[i]);
    }
    int ans = 0;
    while(s.size()){
        auto it = (s.end());
        it--;
        int x = *it;
        if(p >= x){
            int t = k;
            if(s.size() >= k){
                while(s.size() && t){
                    ans++;
                    t--;
                    s.erase((--s.end()));
                }
                p -= x;
            }
            else{
                break;
            }
        }
        else{
            break;
        }
    }
    //debug(mid, ans, p);
    while(s.size()){
        auto it = s.begin();
        int x = *it;
        if(p >= x){
            ans++;
            p -= x;
            s.erase(s.begin());
        }
        else{
            break;
        }
    }
    if(ans < mid) return 0;
    return 1;
}

void solve(){
    int n, p, k;
    cin >> n >> p >> k;
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v, v+n);
    int low = k;
    int high = n;
    int ans = 0;
    while(low <= high){
        int mid = (low+high)/2;
        if(f(mid, p , k)){
            ans = max(ans, mid);
            low = mid+1;
        }
        else{
            high = mid-1;
        }
    }
    int tp = p;
    int tans = 0;
    for(int i = 0 ; i < n; i++){
        if(v[i] <= tp){
            tans++;
            tp -= v[i];
        }
    }
    ans = max(ans, tans);
    vi vv(n+1, 0);
    int fans = 0;
    for(int i = 0; i < k; i++){
        tans = 0;
        tp = p;
        int j = i;
        while(j < n){
            if(j+k-1 < n){
                int s = v[j+k-1];
                if(tp >= s){
                    tans += k;
                    tp -= s;
                }
                else{
                    break;
                }
            }
            else{
                break;
            }
            j += k;
        }
        for(int a = 0; a < i; a++){
            if(tp >= v[a]){
                tans++;
                tp -= v[a];
            }
        }
        for(j; j < n; j++){
            if(tp >= v[j]){
                tans++;
                tp -= v[j];
            }
        }
        ans = max(ans, tans);
    }
    cout << max(ans, tans) << endl;
}
signed main(){
//  freopen("ii.txt", "w", stdin);
    flash;
    int t = 1;
     cin >> t;
    for(int tc = 1; tc <= t; tc++){
    //goog(tc);
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int v[MAX5];

int f(int mid, int p, int k){
    multiset < int > s;
    for(int i = 0; i < mid; i++){
        s.insert(v[i]);
    }
    int ans = 0;
    while(s.size()){
        auto it = (s.end());
        it--;
        int x = *it;
        if(p >= x){
            int t = k;
            if(s.size() >= k){
                while(s.size() && t){
                    ans++;
                    t--;
                    s.erase((--s.end()));
                }
                p -= x;
            }
            else{
                break;
            }
        }
        else{
            break;
        }
    }
    //debug(mid, ans);
    while(s.size()){
        auto it = s.begin();
        int x = *it;
        if(p >= x){
            ans++;
            p -= x;
            s.erase(s.begin());
        }
        else{
            break;
        }
    }
    if(ans < mid) return 0;
    return 1;
}

void solve(){
    int n, p, k;
    cin >> n >> p >> k;
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v, v+n);
    int low = k;
    int high = n;
    int ans = 0;
    while(low <= high){
        int mid = (low+high)/2;
        if(f(mid, p , k)){
            ans = max(ans, mid);
            low = mid+1;
        }
        else{
            high = mid-1;
        }
    }
    int tp = p;
    int tans = 0;
    for(int i = 0 ; i < n; i++){
        if(v[i] <= tp){
            tans++;
            tp -= v[i];
        }
    }
    cout << max(ans, tans) << endl;
}
signed main(){
//  freopen("ii.txt", "w", stdin);
    flash;
    int t = 1;
     cin >> t;
    for(int tc = 1; tc <= t; tc++){
    //goog(tc);
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int v[MAX5];

int f(int mid, int p, int k){
    multiset < int > s;
    for(int i = 0; i < mid; i++){
        s.insert(v[i]);
    }
    int ans = 0;
    while(s.size()){
        auto it = (s.end());
        it--;
        int x = *it;
        if(p >= x){
            int t = k;
            if(s.size() >= k){
                while(s.size() && t){
                    ans++;
                    t--;
                    s.erase((--s.end()));
                }
                p -= x;
            }
            else{
                break;
            }
        }
        else{
            break;
        }
    }
    //debug(mid, ans, p);
    while(s.size()){
        auto it = s.begin();
        int x = *it;
        if(p >= x){
            ans++;
            p -= x;
            s.erase(s.begin());
        }
        else{
            break;
        }
    }
    if(ans < mid) return 0;
    return 1;
}

void solve(){
    int n, p, k;
    cin >> n >> p >> k;
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v, v+n);
    int low = k;
    int high = n;
    int ans = 0;
    while(low <= high){
        int mid = (low+high)/2;
        if(f(mid, p , k)){
            ans = max(ans, mid);
            low = mid+1;
        }
        else{
            high = mid-1;
        }
    }
    int tp = p;
    int tans = 0;
    for(int i = 0 ; i < n; i++){
        if(v[i] <= tp){
            tans++;
            tp -= v[i];
        }
    }
    ans = max(ans, tans);
    vi vv(n+1, 0);
    int fans = 0;
    for(int i = 0; i < k; i++){
        tans = 0;
        tp = p;
        int j = i;
        while(j < n){
            if(j+k-1 < n){
                int s = v[j+k-1];
                if(tp >= s){
                    tans += k;
                    tp -= s;
                }
                else{
                    break;
                }
            }
            else{
                break;
            }
            j += k;
        }
        ans = max(ans, tans);
    }
    cout << max(ans, tans) << endl;
}
signed main(){
//  freopen("ii.txt", "w", stdin);
    flash;
    int t = 1;
     cin >> t;
    for(int tc = 1; tc <= t; tc++){
    //goog(tc);
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int v[MAX5];

void solve(){
    int n, p, k;
    cin >> n >> p >> k;
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v, v+n);
    int low = k;
    int high = n;
    int ans = 0;
    int tp = p;
    int tans = 0;
    for(int i = 0 ; i < n; i++){
        if(v[i] <= tp){
            tans++;
            tp -= v[i];
        }
    }
    ans = max(ans, tans);
    vector < int > vv(n,  0);
    for(int i = 0; i < n; i++){
        if(i == 0) vv[i] = v[i];
        else vv[i]=  vv[i-1]+v[i];
    }
    for(int i = 0; i < k; i++){
        tans = 0;
        tp = p;
        int j = i;
        while(j < n){
            if(j+k-1 < n){
                int s = v[j+k-1];
                if(tp >= s){
                    tans += k;
                    tp -= s;
                }
                else{
                    break;
                }
            }
            else{
                break;
            }
            j += k;
        }
        int it = upper_bound(vv.begin(), vv.begin() + i, tp) - (vv.begin());
        //debug(vv, tp, it);
        tans += it;
        if(it) tp -= v[it-1];
        for(j; j < n; j++){
            if(tp >= v[j]){
                tans++;
                tp -= v[j];
            }
            else break;
        }
        ans = max(ans, tans);
    }
    cout << ans << endl;
}
signed main(){
//  freopen("ii.txt", "w", stdin);
    flash;
    int t = 1;
     cin >> t;
    for(int tc = 1; tc <= t; tc++){
    //goog(tc);
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pll pair<ll,ll>
#define vi vector < int >
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define s(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define pf(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
#define flash ios_base::sync_with_stdio(false);cin.tie(0)
#define goog(x) cout << "Case #" << x << ": "
#define MAX5 200005
#define MAX6 2000005
#define MLOG 18
#define limit 1e18
#define mod 1000000007
void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int power(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int v[MAX5];

void solve(){
    int n, p, k;
    cin >> n >> p >> k;
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(v, v+n);
    int low = k;
    int high = n;
    int ans = 0;
    int tp = p;
    int tans = 0;
    for(int i = 0 ; i < n; i++){
        if(v[i] <= tp){
            tans++;
            tp -= v[i];
        }
    }
    ans = max(ans, tans);
    vector < int > vv(n,  0);
    for(int i = 0; i < n; i++){
        if(i == 0) vv[i] = v[i];
        else vv[i]=  vv[i-1]+v[i];
    }
    for(int i = 0; i < k; i++){
        tans = 0;
        tp = p;
        int j = i;
        while(j < n){
            if(j+k-1 < n){
                int s = v[j+k-1];
                if(tp >= s){
                    tans += k;
                    tp -= s;
                }
                else{
                    break;
                }
            }
            else{
                break;
            }
            j += k;
        }
        int it = upper_bound(vv.begin(), vv.begin() + i, tp) - (vv.begin());
        //debug(vv, tp, it);
        tans += it;
        if(it) tp -= vv[it-1];

        it = upper_bound(vv.begin() + j, vv.begin() + n, tp) - (vv.begin() + j);

        tans += it;
        ans = max(ans, tans);
    }
    cout << ans << endl;
}
signed main(){
//  freopen("ii.txt", "w", stdin);
    flash;
    int t = 1;
     cin >> t;
    for(int tc = 1; tc <= t; tc++){
    //goog(tc);
        solve();
    }
}


/*
		#############################
		#        Problems by :      #
		#        acm.timus.ru       #
		#       codeforces.com      #
		#                           #
		#      Author : Adhambek    #
		#                           #
		#############################
*/
#define _CRT_DISABLE_PERFCRIT_LOCKS
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <time.h>
#include <queue>
#include <map>
#include <set>
#define getc _getchar_nolock()
#define put(c) _putchar_nolock(c)
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
const int INF =  2000000007;
const int inf = -2000000007;
const int mod = 1000000007;
const int mxs = 100100;
const __int64 MOD = 1000000007;
using namespace std;

template <typename T> T gcd(T a, T b){ return a != 0 ? gcd(b % a, a) : b;}
template <typename T> T lcm(T a, T b){ return a / gcd(a, b) * b;}
typedef __int64 ll;
typedef double  dl;
int node[mxs << 4];
int prv[mxs << 4];
int cur[mxs];
int startNode;
void add(int v, int u){
	node[ ++ startNode] = u;
	prv[startNode] = cur[v];
	cur[v] = startNode;
}

void solve(int task);
void solve();
int main(){
	int t = 1;
	//scanf("%d", &t);
	for(int i = 1; i <= t; i ++){
		solve();
	}
}
int n, q;
ll a[mxs];
ll bf[mxs];
ll buf[mxs];
ll dp[mxs];
ll nt[mxs];
int id[mxs];
void solve(){
	scanf("%d %d",&n, &q);
	for(int i = 1; i <= n; i ++)
		scanf("%I64d",a + i);
	while(q --){
		int l, r;
		scanf("%d %d", &l, &r);
		int ln = 1;
		for(int i = l; i < r; i ++)
			buf[ln ++] = abs(a[i] - a[i + 1]);
		ll res = buf[1];
		bf[1] = buf[1];
		dp[1] = buf[1];
		id[1] = 1;
		int lf = 1;
		for(int i = 2; i < ln; i ++){
			while(lf > 0 && bf[lf] <= buf[i]) lf --;
			bf[lf + 1] = buf[i];
			id[lf + 1] = i;
			dp[i] = buf[i] * (i - id[lf]);
			dp[i] += dp[lf];
			dp[lf + 1] = dp[i];
			res += dp[i];
			lf ++;
		}
		printf("%I64d\n",res);
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int a[100005],b[100005];
pair<int,int> q[100005],pii;
int vl[100005],vr[100005],qst,qed;
int main(){
    int i,j,n,m,c,d;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    for(i=1;i<n;i++){
        b[i]=abs(a[i+1]-a[i]);
    }
    b[0]=1e9,b[n]=1e9;
    qst=1,qed=0;
    q[++qed].first=b[0];
    q[qed].second=0;
    for(i=1;i<n;i++){
        while(qst<=qed && q[qed].first<=b[i]) qed--;
        vl[i]=q[qed].second;
        q[++qed].first=b[i];
        q[qed].second=i;
    }
    qst=1,qed=0;
    q[++qed].first=b[n];
    q[qed].second=n;
    for(i=n-1;i>=1;i--){
        while(qst<=qed && q[qed].first<b[i]) qed--;
        vr[i]=q[qed].second;
        q[++qed].first=b[i];
        q[qed].second=i;
    }
    __int64 ans;
    while(m--){
        scanf("%d%d",&c,&d);
        d--;
        ans=0;
        if(c<=d){
            for(i=c;i<=d;i++){
                ans+=1LL*(i-max(vl[i],c-1))*(min(vr[i],d+1)-i)*b[i];
            }
        }
        printf("%I64d\n",ans);
    }
    //system("pause");
    return 0;
}


//#define MYDEBUG
#define _CRT_SECURE_NO_WARNINGS
#define TASK "deb"
#pragma comment(linker, "/STACK:134217728")
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <functional>
#include <cassert>
#include <random>
#include <bitset>

const int MOD = 1000000007;
const int INF = 1000000001;
const int MAXN = 17;
const double EPS = 1e-6;
const int HASH_POW = 31;
const double PI = acos(-1.0);

using namespace std;

void my_return(int code)
{
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
	exit(code);
}

int n, q, a[100010], d[100010], ll[100010], rr[100010];

int main()
{
	cin.sync_with_stdio(0);
	cin.tie(0);
	mt19937 mt_rand(time(NULL));
	#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#else
	/*freopen(TASK".in", "rt", stdin);
	freopen(TASK".out", "wt", stdout);*/
	/*freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);*/
	#endif

	scanf("%d %d", &n, &q);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for (int i = 2; i <= n; ++i)
		d[i] = abs(a[i] - a[i - 1]);

	stack <int> s;
	for (int i = 2; i <= n; ++i)
	{
		while (!s.empty() && d[s.top()] <= d[i])
			s.pop();
		if (s.empty())
			ll[i] = -1;
		else
			ll[i] = s.top();
		s.push(i);
	}
	while (!s.empty())
		s.pop();
	for (int i = n; i >= 2; --i)
	{
		while (!s.empty() && d[s.top()] < d[i])
			s.pop();
		if (s.empty())
			rr[i] = -1;
		else
			rr[i] = s.top();
		s.push(i);
	}

	while (q--)
	{
		int l, r;
		scanf("%d %d", &l, &r);

		long long ans = 0;
		for (int i = l + 1; i <= r; ++i)
		{
			int cntl = 0, cntr = 0;
			if (ll[i] == -1 || ll[i] <= l)
				cntl = i - l;
			else
				cntl = i - ll[i];
			if (rr[i] == -1 || rr[i] > r)
				cntr = r - i + 1;
			else
				cntr = rr[i] - i;
			ans += d[i]*1ll*cntl*cntr;
		}

		printf("%I64d\n", ans);
	}

	my_return(0);
}


//#define MYDEBUG
#define _CRT_SECURE_NO_WARNINGS
#define TASK "deb"
#pragma comment(linker, "/STACK:134217728")
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <functional>
#include <cassert>
#include <random>
#include <bitset>

const int MOD = 1000000007;
const int INF = 1000000001;
const int MAXN = 17;
const double EPS = 1e-6;
const int HASH_POW = 31;
const double PI = acos(-1.0);

using namespace std;

void my_return(int code)
{
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
	exit(code);
}

int n, q, a[100010], d[100010], ll[100010], rr[100010];

int main()
{
	cin.sync_with_stdio(0);
	cin.tie(0);
	mt19937 mt_rand(time(NULL));
	#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#else
	/*freopen(TASK".in", "rt", stdin);
	freopen(TASK".out", "wt", stdout);*/
	/*freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);*/
	#endif

	scanf("%d %d", &n, &q);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	for (int i = 2; i <= n; ++i)
		d[i] = abs(a[i] - a[i - 1]);

	stack <int> s;
	for (int i = 2; i <= n; ++i)
	{
		while (!s.empty() && d[s.top()] <= d[i])
			s.pop();
		if (s.empty())
			ll[i] = -1;
		else
			ll[i] = s.top();
		s.push(i);
	}
	while (!s.empty())
		s.pop();
	for (int i = n; i >= 2; --i)
	{
		while (!s.empty() && d[s.top()] <= d[i])
			s.pop();
		if (s.empty())
			rr[i] = -1;
		else
			rr[i] = s.top();
		s.push(i);
	}

	while (q--)
	{
		int l, r;
		scanf("%d %d", &l, &r);

		long long ans = 0;
		for (int i = l + 1; i <= r; ++i)
		{
			int cntl = 0, cntr = 0;
			if (ll[i] == -1 || ll[i] <= l)
				cntl = i - l;
			else
				cntl = i - ll[i];
			if (rr[i] == -1 || rr[i] > r)
				cntr = r - i + 1;
			else
				cntr = rr[i] - i;
			ans += d[i]*1ll*cntl*cntr;
		}

		printf("%I64d\n", ans);
	}

	my_return(0);
}


#pragma comment (linker, "/STACK:64000000")

#define _USE_MATH_DEFINES
#define _CRT_NO_DEPRECEATE
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <memory.h>
#include <sstream>
#include <cassert>
#include <ctime>
#include <complex>

#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define piiii pair<pii, pii>
#define mp make_pair
#define sq(x) ((x)*(x))
#define tmin(x,y,z) (min(min((x),(y)),(z)))
#define rand32() (((unsigned int)(rand()) << 16) | (unsigned int)(rand()))
#define rand64() (((unsigned int64)(rand32()) << 16) | (unsigned int64)(rand32()))
#define INF ((int)(1e9))
#define LINF ((long long)(1e15))
#define EPS (1e-8)
#define PI (3.1415926535897932384626433832795)
#define y1 asdf_1
#define y0 asdf_2
#define j0 jj0
#define MOD 1000000007LL
//#define HMOD 536870911
#define HMOD ((long long)(1e18) + 3LL)
//#ifdef _MY_DEBUG
//#define HMOD 1000000007
//#endif
#define MAX 2000000000
#define HBASE 1009

typedef long long int64;
typedef unsigned long long uint64;
typedef long double ldd;
#define long hui

using namespace std;

int n, q;
int a[100010];
int64 d[100010];
int st[100010];
int sz;
int tl[100010];
int tr[100010];

void solve()
{
	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n - 1; i++)
		d[i] = abs(a[i + 1] - a[i]);

	for (int i = 0; i < n - 1; i++)
	{
		while (sz && d[st[sz - 1]] < d[i])
		{
			sz--;
		}
		if (sz)
			tl[i] = st[sz - 1];
		else
			tl[i] = -1;
		st[sz++] = i;
	}
	sz = 0;
	for (int i = n - 2; i >= 0; i--)
	{
		while (sz && d[st[sz - 1]] <= d[i])
			sz--;
		if (sz)
			tr[i] = st[sz - 1];
		else
			tr[i] = n - 1;
		st[sz++] = i;
	}
	for (int i = 0; i < q; i++)
	{
		int64 res = 0;
		int l, r;
		cin >> l >> r;
		l--; r--;
		for (int j = l; j < r; j++)
		{
			int bl = max(l - 1, tl[j]);
			int br = min(r, tr[j]);
			//cout << (j - bl) * (br - j) << endl;
			res += (j - bl) * (br - j) * d[j];
		}
		cout << res << endl;
	}
}

int main()
{
	//testgen(1000000);
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _MY_DEBUG
	freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else
	//freopen(TASK ".in", "rt", stdin); freopen(TASK ".out", "wt", stdout);
#endif
	srand(1337);
	solve();
	return 0;
}


#pragma comment (linker, "/STACK:64000000")

#define _USE_MATH_DEFINES
#define _CRT_NO_DEPRECEATE
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <memory.h>
#include <sstream>
#include <cassert>
#include <ctime>
#include <complex>

#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define piiii pair<pii, pii>
#define mp make_pair
#define sq(x) ((x)*(x))
#define tmin(x,y,z) (min(min((x),(y)),(z)))
#define rand32() (((unsigned int)(rand()) << 16) | (unsigned int)(rand()))
#define rand64() (((unsigned int64)(rand32()) << 16) | (unsigned int64)(rand32()))
#define INF ((int)(1e9))
#define LINF ((long long)(1e15))
#define EPS (1e-8)
#define PI (3.1415926535897932384626433832795)
#define y1 asdf_1
#define y0 asdf_2
#define j0 jj0
#define MOD 1000000007LL
//#define HMOD 536870911
#define HMOD ((long long)(1e18) + 3LL)
//#ifdef _MY_DEBUG
//#define HMOD 1000000007
//#endif
#define MAX 2000000000
#define HBASE 1009

typedef long long int64;
typedef unsigned long long uint64;
typedef long double ldd;
#define long hui

using namespace std;

int n, q;
int a[100010];
int64 d[100010];
int st[100010];
int sz;
int tl[100010];
int tr[100010];

void solve()
{
    cin >> n >> q;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < n - 1; i++)
        d[i] = abs(a[i + 1] - a[i]);

    for (int i = 0; i < n - 1; i++)
    {
        while (sz && d[st[sz - 1]] < d[i])
        {
            sz--;
        }
        if (sz)
            tl[i] = st[sz - 1];
        else
            tl[i] = -1;
        st[sz++] = i;
    }
    sz = 0;
    for (int i = n - 2; i >= 0; i--)
    {
        while (sz && d[st[sz - 1]] <= d[i])
            sz--;
        if (sz)
            tr[i] = st[sz - 1];
        else
            tr[i] = n - 1;
        st[sz++] = i;
    }
    for (int i = 0; i < q; i++)
    {
        int64 res = 0;
        int l, r;
        cin >> l >> r;
        l--; r--;
        for (int j = l; j < r; j++)
        {
            int bl = max(l - 1, tl[j]);
            int br = min(r, tr[j]);
            //cout << (j - bl) * (br - j) << endl;
            res += (int64)(j - bl) * (int64)(br - j) * d[j];
        }
        cout << res << endl;
    }
}

int main()
{
    //testgen(1000000);
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _MY_DEBUG
    freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else
    //freopen(TASK ".in", "rt", stdin); freopen(TASK ".out", "wt", stdout);
#endif
    srand(1337);
    solve();
    return 0;
}


#include <cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int l[maxn], r[maxn], a[maxn], s[maxn],pos[maxn];
int n, q,top,x,y;
int main()
{
    scanf("%d%d%d", &n, &q,&y);
    for (int i = 1; i < n; i++)
    {
        scanf("%d", &x);
        a[i] = abs(x - y);
        y = x;
    }
    s[0] = 1e9; pos[0] = 0;
    for (int i = 1; i < n; i++)
    {
        while (top>0 && s[top]<a[i])
            top--;
        l[i] = i-pos[top];
        top++;
        s[top] = a[i];
        pos[top] = i;
    }
    s[0] = 1e9; pos[0] = n; top = 0;
    for (int i = n - 1; i > 0; i--)
    {
        while (top>0 && s[top] <= a[i])
            top--;
        r[i] = pos[top]-i;
        top++;
        s[top] = a[i];
        pos[top] = i;
    }
    while (q--)
    {
        scanf("%d%d", &x, &y);
        y--;
        long long ans = 0;
        for (int i = x; i <= y; i++)
        {
            long long  ll= max(x - 1, i-l[i]);
            long long  rr = min(y+1,i+r[i]);
            //printf("%I64d %I64d\n", ll, rr);
            ans += a[i] * (i-ll)*(rr-i);
        }
        printf("%I64d\n", ans);
    }
    return 0;
}


#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 20;
struct node
{
    long long sum, v, pos;
};
stack<node> s;
int h[maxn];
int main()
{
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; i++)scanf("%d", &h[i]);
    while (q--)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        while (!s.empty())s.pop();
        node tt; tt.pos = l; tt.sum = 0; tt.v = 0;
        s.push(tt);
        long long ans = 0, t;
        int v;
        for (int i = l + 1; i <= r; i++)
        {
            v = abs(h[i] - h[i - 1]);
            while (s.size() > 1 && s.top().v < v)s.pop();
            t = s.top().sum + v*(i - s.top().pos);
            ans += t;
            tt.sum = t; tt.v = v; tt.pos = i;
            s.push(tt);
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=100000+500;
int n,m,a[maxn],b[maxn],l[maxn],r[maxn];
int w[maxn],w1[maxn],w0;
int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=abs(a[i]-a[i-1]);
	}
	w0=1;w[0]=1<<30;w1[0]=1;
	for (int i=2;i<=n;i++)
	{
		while (b[i]>=w[w0-1])
		    w0--;
		l[i]=w1[w0-1]+1;
		w[w0]=b[i];
		w1[w0]=i;
		w0++;
	}
	w0=1;w[0]=1<<30;w1[0]=n+1;
	for (int i=n;i>=2;i--)
	{
		while (b[i]>w[w0-1])
		    w0--;
		r[i]=w1[w0-1]-1;
		w[w0]=b[i];
		w1[w0]=i;
		w0++;
	}
	for (int i=1;i<=m;i++)
	{
		long long ans=0;
		int u,v;
		scanf("%d%d",&u,&v);
		if (u==v)
		    ans=0;
		else
		for (int k=u+1;k<=v;k++)
		{
		    int u1=max(u+1,l[k]),v1=min(v,r[k]);
			long long tt1=b[k],tt2=v1-k+1,tt3=k-u1+1;
			ans+=tt1*tt2*tt3;
		}
		cout<<ans<<endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:36777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>

typedef long long ll;

using namespace std;
inline ll MAX(ll a, ll b) { return (a > b) ? (a) : (b); }
inline ll MIN(ll a, ll b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define sd second
#define ft first
#define mp make_pair
stack<pair<ll, ll> > st;

int main()
{
	int const sz = 2e5;
	ll i, j, a[sz + 1], l[sz + 1], r[sz + 1], u, d[sz + 1], b, n, q,x[101],y[101];

	scanf_s("%I64d %I64d", &n, &q);
	rep(i, 1, n) scanf_s("%I64d", &a[i]);

	rep(i, 1, n - 1) d[i] = abs(a[i] - a[i + 1]);

	st.push(mp(1e9, 0));

	rep(i, 1, n-1)
	{
		while (st.top().ft < d[i]) st.pop();
		u = st.top().sd; l[i] = u+1;
		st.push(mp(d[i], i));
	}

	while (!st.empty()) st.pop();

	st.push(mp(1e9, n));

	brep(i, n-1, 1)
	{
		while (st.top().ft <= d[i]) st.pop();
		u = st.top().sd; r[i] = u-1;
		st.push(mp(d[i], i));
	}
	ll ans,lll,rrr;
	rep(i, 1, q) scanf_s("%I64d %I64d", &x[i], &y[i]);

	rep(i, 1, q)
	{
		ans = 0;

		rep(j, x[i], y[i]-1)
		{
			lll = MAX(l[j], x[i]); rrr = MIN(r[j], y[i]-1);
			ans += (j-lll+1)*(rrr-j+1)*d[j];
		}
		printf("%I64d\n", ans);
	}

	return 0;
}


#pragma comment(linker, "/STACK:36777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>

typedef long long ll;

using namespace std;
inline ll MAX(ll a, ll b) { return (a > b) ? (a) : (b); }
inline ll MIN(ll a, ll b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define sd second
#define ft first
#define mp make_pair
stack<pair<ll, ll> > st;

int main()
{
	int const sz = 2e5;
	ll i, j, a[sz + 1], l[sz + 1], r[sz + 1], u, d[sz + 1], b, n, q,x[101],y[101];

	scanf_s("%d %d", &n, &q);
	rep(i, 1, n) scanf_s("%d", &a[i]);

	rep(i, 1, n - 1) d[i] = abs(a[i] - a[i + 1]);

	st.push(mp(1e9, 0));

	rep(i, 1, n-1)
	{
		while (st.top().ft < d[i]) st.pop();
		u = st.top().sd; l[i] = u+1;
		st.push(mp(d[i], i));
	}

	while (!st.empty()) st.pop();

	st.push(mp(1e9, n));

	brep(i, n-1, 1)
	{
		while (st.top().ft <= d[i]) st.pop();
		u = st.top().sd; r[i] = u-1;
		st.push(mp(d[i], i));
	}
	ll ans,lll,rrr;
	rep(i, 1, q) scanf_s("%d %d", &x[i], &y[i]);

	rep(i, 1, q)
	{
		ans = 0;

		rep(j, x[i], y[i]-1)
		{
			lll = MAX(l[j], x[i]); rrr = MIN(r[j], y[i]-1);
			ans += (j-lll+1)*(rrr-j+1)*d[j];
		}
		printf("%d\n", ans);
	}

	return 0;
}


#pragma comment(linker, "/STACK:36777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>

typedef long long ll;

using namespace std;
inline int MAX(int a, int b) { return (a > b) ? (a) : (b); }
inline int MIN(int a, int b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define sd second
#define ft first
#define mp make_pair
stack<pair<int, int> > st;

int main()
{
	int const sz = 1e5;
	int i, j, a[sz + 1], l[sz + 1], r[sz + 1], u, d[sz + 1], b, n, q,x[101],y[101];

	scanf_s("%d %d", &n, &q);
	rep(i, 1, n) scanf_s("%d", &a[i]);

	rep(i, 1, n - 1) d[i] = abs(a[i] - a[i + 1]);

	st.push(mp(1e9, 0));

	rep(i, 1, n-1)
	{
		while (st.top().ft < d[i]) st.pop();
		u = st.top().sd; l[i] = u+1;
		st.push(mp(d[i], i));
	}

	while (!st.empty()) st.pop();

	st.push(mp(1e9, n));

	brep(i, n-1, 1)
	{
		while (st.top().ft <= d[i]) st.pop();
		u = st.top().sd; r[i] = u-1;
		st.push(mp(d[i], i));
	}
	ll ans,lll,rrr;
	rep(i, 1, q) scanf_s("%d %d", &x[i], &y[i]);

	rep(i, 1, q)
	{
		ans = 0;

		rep(j, x[i], y[i]-1)
		{
			lll = MAX(l[j], x[i]); rrr = MIN(r[j], y[i]-1);
			ans += (j-lll+1)*(rrr-j+1)*d[j];
		}
		printf("%d\n", ans);
	}

	return 0;
}


#pragma comment(linker, "/STACK:36777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>

typedef long long ll;

using namespace std;
inline int MAX(int a, int b) { return (a > b) ? (a) : (b); }
inline int MIN(int a, int b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define sd second
#define ft first
#define mp make_pair
stack<pair<int, int> > st;

int main()
{
	int const sz = 100;
	int i, j, a[sz + 1], l[sz + 1], r[sz + 1], u, d[sz + 1], b, n, q,x[101],y[101];

	scanf_s("%d %d", &n, &q);
	rep(i, 1, n) scanf_s("%d", &a[i]);

	rep(i, 1, n - 1) d[i] = abs(a[i] - a[i + 1]);

	st.push(mp(1e9, 0));

	rep(i, 1, n-1)
	{
		while (st.top().ft < d[i]) st.pop();
		u = st.top().sd; l[i] = u+1;
		st.push(mp(d[i], i));
	}

	while (!st.empty()) st.pop();

	st.push(mp(1e9, n));

	brep(i, n-1, 1)
	{
		while (st.top().ft <= d[i]) st.pop();
		u = st.top().sd; r[i] = u-1;
		st.push(mp(d[i], i));
	}
	ll ans,lll,rrr;
	rep(i, 1, q) scanf_s("%d %d", &x[i], &y[i]);

	rep(i, 1, q)
	{
		ans = 0;

		rep(j, x[i], y[i]-1)
		{
			lll = MAX(l[j], x[i]); rrr = MIN(r[j], y[i]-1);
			ans += (j-lll+1)*(rrr-j+1)*d[j];
		}
		printf("%d\n", ans);
	}

	return 0;
}


#pragma comment(linker, "/STACK:36777216")
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>

typedef long long ll;

using namespace std;
inline ll MAX(ll a, ll b) { return (a > b) ? (a) : (b); }
inline ll MIN(ll a, ll b) { return (a < b) ? (a) : (b); }

#define rep(i,a,b) for(i=a; i<=b; i++)
#define brep(i,b,a) for(i=b; i>=a; i--)
#define sd second
#define ft first
#define mp make_pair
stack<pair<ll, ll> > st;

int main()
{
	int const sz = 1e5;
	ll i, j, a[sz + 1], l[sz + 1], r[sz + 1], u, d[sz + 1], b, n, q,x[101],y[101];

	scanf_s("%d %d", &n, &q);
	rep(i, 1, n) scanf_s("%d", &a[i]);

	rep(i, 1, n - 1) d[i] = abs(a[i] - a[i + 1]);

	st.push(mp(1e9, 0));

	rep(i, 1, n-1)
	{
		while (st.top().ft < d[i]) st.pop();
		u = st.top().sd; l[i] = u+1;
		st.push(mp(d[i], i));
	}

	while (!st.empty()) st.pop();

	st.push(mp(1e9, n));

	brep(i, n-1, 1)
	{
		while (st.top().ft <= d[i]) st.pop();
		u = st.top().sd; r[i] = u-1;
		st.push(mp(d[i], i));
	}
	ll ans,lll,rrr;
	rep(i, 1, q) scanf_s("%d %d", &x[i], &y[i]);

	rep(i, 1, q)
	{
		ans = 0;

		rep(j, x[i], y[i]-1)
		{
			lll = MAX(l[j], x[i]); rrr = MIN(r[j], y[i]-1);
			ans += (j-lll+1)*(rrr-j+1)*d[j];
		}
		printf("%d\n", ans);
	}

	return 0;
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>

#define N	100000

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand(tv.tv_sec ^ tv.tv_usec);
}

int rand_(int n) {
	return (rand() * 76543LL + rand()) % n;
}

int aa[N + 1];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return aa[i] - aa[j];
}

int ii[N];

long long solve(int n, int ql, int qr) {
	static int ll[N + 2], rr[N + 2];
	static char used[N + 2];
	int h, i, l, r;
	long long ans;

	for (i = ql - 1; i <= qr + 1; i++) {
		ll[i] = rr[i] = i;
		used[i] = 0;
	}
	ans = 0;
	for (h = 0; h < n; h++) {
		i = ii[h];
		if (i < ql || i > qr)
			continue;
		l = r = i;
		used[i] = 1;
		if (used[i - 1])
			l = ll[i - 1];
		if (used[i + 1])
			r = rr[i + 1];
		rr[l] = r, ll[r] = l;
		ans += (long long) (i - l + 1) * (r - i + 1) * aa[i];
	}
	return ans;
}

int main() {
	int n, q, h, i, j, tmp;

	srand_();
	scanf("%d%d", &n, &q);
	for (i = 1; i <= n; i++)
		scanf("%d", &aa[i]);
	for (i = 1; i <= n - 1; i++)
		aa[i] = abs(aa[i + 1] - aa[i]);
	n--;
	for (h = 0; h < n; h++)
		ii[h] = h + 1;
	for (i = 0; i < n; i++) {
		j = rand_(i + 1);
		tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
	}
	qsort(ii, n, sizeof *ii, compare);
	while (q--) {
		int l, r;

		scanf("%d%d", &l, &r);
		printf("%lld\n", solve(n, l, r - 1));
	}
	return 0;
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#define N	100000

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand(tv.tv_sec ^ tv.tv_usec);
}

int rand_(int n) {
	return (rand() * 76543LL + rand()) % n;
}

int *aa_;

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return aa_[i] - aa_[j];
}

long long solve(int *aa, int n) {
	static int ii[N], ll[N + 2], rr[N + 2];
	static char used[N + 2];
	int h, i, j, l, r, tmp;
	long long ans;

	for (h = 0; h < n; h++)
		ii[h] = h + 1;
	for (i = 0; i < n; i++) {
		j = rand_(i + 1);
		tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
	}
	aa_ = aa;
	qsort(ii, n, sizeof *ii, compare);
	for (i = 0; i < n + 2; i++)
		ll[i] = rr[i] = i;
	memset(used, 0, (n + 2) * sizeof *used);
	ans = 0;
	for (h = 0; h < n; h++) {
		i = ii[h];
		l = r = i;
		used[i] = 1;
		if (used[i - 1])
			l = ll[i - 1];
		if (used[i + 1])
			r = rr[i + 1];
		rr[l] = r, ll[r] = l;
		ans += (long long) (i - l + 1) * (r - i + 1) * aa[i];
	}
	return ans;
}

int main() {
	static int aa[N], bb[N + 2];
	int n, q, i, j, l, r;

	srand_();
	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i < n - 1; i++)
		aa[i] = abs(aa[i + 1] - aa[i]);
	n--;
	while (q--) {
		int m;

		scanf("%d%d", &l, &r), l--, r--;
		m = r - l;
		for (j = 0; j < m; j++)
			bb[1 + j] = aa[l + j];
		printf("%lld\n", solve(bb, m));
	}
	return 0;
}


/* practice with Dukkha */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#define N	100000

void srand_() {
	struct timeval tv;

	gettimeofday(&tv, NULL);
	srand(tv.tv_sec ^ tv.tv_usec);
}

int rand_(int n) {
	return (rand() * 76543LL + rand()) % n;
}

int aa[N], o;

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return aa[o + i - 1] - aa[o + j - 1];
}

long long solve(int n) {
	static int ii[N], ll[N + 2], rr[N + 2];
	static char used[N + 2];
	int h, i, j, l, r, tmp;
	long long ans;

	for (h = 0; h < n; h++)
		ii[h] = h + 1;
	for (i = 0; i < n; i++) {
		j = rand_(i + 1);
		tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
	}
	qsort(ii, n, sizeof *ii, compare);
	for (i = 0; i < n + 2; i++)
		ll[i] = rr[i] = i;
	memset(used, 0, (n + 2) * sizeof *used);
	ans = 0;
	for (h = 0; h < n; h++) {
		i = ii[h];
		l = r = i;
		used[i] = 1;
		if (used[i - 1])
			l = ll[i - 1];
		if (used[i + 1])
			r = rr[i + 1];
		rr[l] = r, ll[r] = l;
		ans += (long long) (i - l + 1) * (r - i + 1) * aa[o + i - 1];
	}
	return ans;
}

int main() {
	int n, q, i, l, r;

	srand_();
	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i < n - 1; i++)
		aa[i] = abs(aa[i + 1] - aa[i]);
	n--;
	while (q--) {
		scanf("%d%d", &l, &r), l--, r--;
		o = l;
		printf("%lld\n", solve(r - l));
	}
	return 0;
}


f = lambda: map(int, input().split())
n, m = f()
t = list(f())
p = [1e9] + [abs(b - a) for a, b in zip(t, t[1:])] + [1e9]
L, R = [0] * n, [0] * n
for i in range(1, n):
    j = n - i
    x, y = i - 1, j + 1
    a, b = p[i], p[j]
    while a > p[x]: x = L[x]
    while b >= p[y]: y = R[y]
    L[i], R[j] = x, y
for k in range(m):
    l, r = f()
    print(sum((i - max(l - 1, L[i])) * (min(r, R[i]) - i) * p[i] for i in range(l, r)))


def read_data():
    n, q = map(int, input().split())
    As = list(map(int, input().split()))
    LRs = []
    for i in range(q):
        L, R = list(map(int, input().split()))
        LRs.append((L, R))
    return n, q, As, LRs

def solve(n, q, As, LRs):
    difs = calc_difs(As)
    Ls = get_Ls(difs)
    Rs = get_Rs_allow_ties(difs)
    for L, R in LRs:
        print(calc(L-1, R-2, Ls, Rs, difs))

def calc_difs(As):
    difs = [abs(a0 - a1) for a0, a1 in zip(As, As[1:])]
    return difs

def get_Ls(Vs):
    L = []
    st = []
    for i, v in enumerate(Vs):
        while st and Vs[st[-1]] < v:
            st.pop()
        if st:
            L.append(st[-1] + 1)
        else:
            L.append(0)
        st.append(i)
    return L

def get_Ls_allow_ties(Vs):
    L = []
    st = []
    for i, v in enumerate(Vs):
        while st and Vs[st[-1]] <= v:
            st.pop()
        if st:
            L.append(st[-1] + 1)
        else:
            L.append(0)
        st.append(i)
    return L

def get_Rs(Vs):
    n = len(Vs)
    revVs = Vs[::-1]
    revRs = get_Ls(revVs)
    revRs.reverse()
    return [n - 1 - R for R in revRs]

def get_Rs_allow_ties(Vs):
    n = len(Vs)
    revVs = Vs[::-1]
    revRs = get_Ls_allow_ties(revVs)
    revRs.reverse()
    return [n - 1 - R for R in revRs]

def calc(L, R, Ls, Rs, difs):
    ans = 0
    for i in range(L, R + 1):
        ans += difs[i] * (i - max(Ls[i], L) + 1) * (min(Rs[i], R) - i + 1)
    return ans

n, q, As, LRs = read_data()
solve(n, q, As, LRs)


f = lambda: map(int, input().split())
n, m = f()
t = list(f())
p = [abs(b - a) for a, b in zip(t, t[1:])]
n -= 1
L, R = [0] * n, [0] * n
for i in range(n):
    q = p[i]
    x = i - 1
    while x >= 0 and q > p[x]: x -= 1
    L[i] = x
    y = i + 1
    while y < n and q >= p[y]: y += 1
    R[i] = y
for k in range(m):
    l, r = f()
    l -= 1
    r -= 1
    s = 0
    for i in range(l, r):
        q = p[i]
        x = max(l - 1, L[i])
        y = min(r, R[i])
        s += (i - x) * (y - i) * q
    print(s)


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
	internal class Template
	{
		private int[] b;

		private void Solve()
		{
			var n = cin.NextInt();
			var q = cin.NextInt();
			var a = new int[n];
			for (var i = 0; i < n; i++)
			{
				a[i] = cin.NextInt();
			}
			b = new int[n - 1];
			var bb = new int[n - 1];
			for (var i = 0; i < b.Length; i++)
			{
				b[i] = Math.Abs(a[i] - a[i + 1]);

				bb[i] = -b[i];
			}

			rmq = new RmqSparseTable(bb);

			for (var i = 0; i < q; i++)
			{
				var l = cin.NextInt() - 1;
				var r = cin.NextInt() - 2;

				var stack = new List<Pos>();
				stack.Add(new Pos { L = l, R = r});
				var result = 0L;
				for (var j = 0; j < stack.Count; j++)
				{
					l = stack[j].L;
					r = stack[j].R;
					var maxIdx = rmq.minPos(l, r);
					var maxValue = b[maxIdx];
					var left = maxIdx - l + 1;
					var right = r - maxIdx + 1;
					result += (long)maxValue * left * right;
					if (l <= maxIdx - 1)
					{
						stack.Add(new Pos { L = l, R = maxIdx - 1});
					}
					if (maxIdx + 1 <= r)
					{
						stack.Add(new Pos { L = maxIdx + 1, R = r });
					}
				}

				Console.WriteLine(result);
			}
		}

		public struct Pos
		{
			public int L;
			public int R;
		}

		private RmqSparseTable rmq;

		public class RmqSparseTable
		{

			int[] logTable;
			int[,] rmq;
			int[] a;

			public RmqSparseTable(int[] a) {
    this.a = a;
    int n = a.Length;

    logTable = new int[n + 1];
    for (int i = 2; i <= n; i++)
      logTable[i] = logTable[i >> 1] + 1;

    rmq = new int[logTable[n] + 1,n];

    for (int i = 0; i < n; ++i)
      rmq[0,i] = i;

    for (int k = 1; (1 << k) < n; ++k) {
      for (int i = 0; i + (1 << k) <= n; i++) {
        int x = rmq[k - 1,i];
        int y = rmq[k - 1,i + (1 << k - 1)];
        rmq[k,i] = a[x] <= a[y] ? x : y;
      }
    }
  }

			public int minPos(int i, int j)
			{
				int k = logTable[j - i];
				int x = rmq[k,i];
				int y = rmq[k,j - (1 << k) + 1];
				return a[x] <= a[y] ? x : y;
			}
		}

		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if DEBUG
			var inputText = File.ReadAllText(@"..\..\input.txt");
			var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
			var consoleOut = Console.Out;
			for (var i = 0; i < testCases.Length; i++)
			{
				var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
				Console.SetIn(new StringReader(parts[0].Trim()));
				var stringWriter = new StringWriter();
				Console.SetOut(stringWriter);
				var sw = Stopwatch.StartNew();
				new Template().Solve();
				sw.Stop();
				var output = stringWriter.ToString();

				Console.SetOut(consoleOut);
				var color = ConsoleColor.Green;
				var status = "Passed";
				if (parts[1].Trim() != output.Trim())
				{
					color = ConsoleColor.Red;
					status = "Failed";
				}
				Console.ForegroundColor = color;
				Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
			}
			Console.ReadLine();
			Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(NextString());
		}

		public int NextInt()
		{
			return int.Parse(NextString());
		}

		public long NextLong()
		{
			return long.Parse(NextString());
		}
	}
}


using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Codeforces
{
	internal class Template
	{
		private int[] b;

		private void Solve()
		{
			var n = cin.NextInt();
			var q = cin.NextInt();
			var a = new int[n];
			for (var i = 0; i < n; i++)
			{
				a[i] = cin.NextInt();
			}
			b = new int[n - 1];
			for (var i = 0; i < b.Length; i++)
			{
				b[i] = Math.Abs(a[i] - a[i + 1]);
			}
			for (var i = 0; i < q; i++)
			{
				var l = cin.NextInt() - 1;
				var r = cin.NextInt() - 2;

				var result = Sum(l, r);
				Console.WriteLine(result);
			}
		}

		private long Sum(int l, int r)
		{
			if (l > r)
			{
				return 0;
			}
			var maxValue = int.MinValue;
			var maxIdx = -1;
			for (var i = l; i <= r; i++)
			{
				if (b[i] > maxValue)
				{
					maxValue = b[i];
					maxIdx = i;
				}
			}
			var left = maxIdx - l + 1;
			var right = r - maxIdx + 1;
			var sum = (long) maxValue*left*right;
			sum += Sum(l, maxIdx - 1);
			sum += Sum(maxIdx + 1, r);
			return sum;
		}

		private static readonly Scanner cin = new Scanner();

		private static void Main()
		{
#if DEBUG
			var inputText = File.ReadAllText(@"..\..\input.txt");
			var testCases = inputText.Split(new[] { "input" }, StringSplitOptions.RemoveEmptyEntries);
			var consoleOut = Console.Out;
			for (var i = 0; i < testCases.Length; i++)
			{
				var parts = testCases[i].Split(new[] { "output" }, StringSplitOptions.RemoveEmptyEntries);
				Console.SetIn(new StringReader(parts[0].Trim()));
				var stringWriter = new StringWriter();
				Console.SetOut(stringWriter);
				var sw = Stopwatch.StartNew();
				new Template().Solve();
				sw.Stop();
				var output = stringWriter.ToString();

				Console.SetOut(consoleOut);
				var color = ConsoleColor.Green;
				var status = "Passed";
				if (parts[1].Trim() != output.Trim())
				{
					color = ConsoleColor.Red;
					status = "Failed";
				}
				Console.ForegroundColor = color;
				Console.WriteLine("Test {0} {1} in {2}ms", i + 1, status, sw.ElapsedMilliseconds);
			}
			Console.ReadLine();
			Console.ReadKey();
#else
			new Template().Solve();
			Console.ReadLine();
#endif
		}
	}

	internal class Scanner
	{
		private string[] s = new string[0];
		private int i;
		private readonly char[] cs = { ' ' };

		public string NextString()
		{
			if (i < s.Length) return s[i++];
			var line = Console.ReadLine() ?? string.Empty;
			s = line.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			i = 1;
			return s.First();
		}

		public double NextDouble()
		{
			return double.Parse(NextString());
		}

		public int NextInt()
		{
			return int.Parse(NextString());
		}

		public long NextLong()
		{
			return long.Parse(NextString());
		}
	}
}


using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Debug;
using StringBuilder = System.Text.StringBuilder;
using System.Numerics;
using Point = System.Numerics.Complex;
namespace Program
{

    public class Solver
    {
        public void Solve()
        {
            var n = sc.Integer();
            var q = sc.Integer();
            var a = sc.Long(n);
            var b = new Pair<long, int>[n - 1];
            for (int i = 0; i < n - 1; i++)
                b[i] = new Pair<long, int>(Math.Abs(a[i + 1] - a[i]), i);
            Array.Sort(b);
            Array.Reverse(b);
            var L = new int[q];
            var R = new int[q];
            for (int i = 0; i < q; i++)
            {
                L[i] = sc.Integer() - 1;
                R[i] = sc.Integer() - 1;
            }
            var ans = new long[q];
            var set = new AVLTree();
            set.Add(-1);
            set.Add(n - 1);
            for (int i = 0; i < n - 1; i++)
            {
                var val = b[i].x;
                var pos = b[i].y;
                var ub = set.UpperBound(pos);
                var l = 1 + set[ub - 1];
                var r = set[ub];

                for (int j = 0; j < q; j++)
                {
                    var ql = Math.Max(L[j], l);
                    var qr = Math.Min(R[j], r);
                    if (ql <= pos && pos + 1 <= qr)
                        ans[j] += (pos - ql + 1) * (qr - pos) * val;
                }
                set.Add(pos);
            }
            foreach(var x in ans)
                IO.Printer.Out.WriteLine(x);
        }
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());
        static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(i); return a; }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}

#region Ex
namespace Program.IO
{
    using System.IO;
    using System.Text;
    using System.Globalization;
    public class Printer : StreamWriter
    {
        static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; }
        public static Printer Out { get; set; }
        public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
        public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
        public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
        public void Write<T>(string format, IEnumerable<T> source) { base.Write(format, source.OfType<object>().ToArray()); }
        public void WriteLine<T>(string format, IEnumerable<T> source) { base.WriteLine(format, source.OfType<object>().ToArray()); }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } }
            return buf[ptr++];
        }
        public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; }

        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            if (isEof) return long.MinValue;
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (isEof) ? int.MinValue : (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
        private T[] enumerate<T>(int n, Func<T> f)
        {
            var a = new T[n];
            for (int i = 0; i < n; ++i) a[i] = f();
            return a;
        }

        public char[] Char(int n) { return enumerate(n, Char); }
        public string[] Scan(int n) { return enumerate(n, Scan); }
        public double[] Double(int n) { return enumerate(n, Double); }
        public int[] Integer(int n) { return enumerate(n, Integer); }
        public long[] Long(int n) { return enumerate(n, Long); }
    }
}

static class Ex
{
    static public string AsString(this IEnumerable<char> ie) { return new string(System.Linq.Enumerable.ToArray(ie)); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); }
    static public void Main()
    {
        var solver = new Program.Solver();
        solver.Solve();
        Program.IO.Printer.Out.Flush();
    }
}
#endregion
#region Compair
static public class Pair
{
    static public Pair<FT, ST> Create<FT, ST>(FT f, ST s)
        where FT : IComparable<FT>
        where ST : IComparable<ST>
    { return new Pair<FT, ST>(f, s); }
    static public Pair<FT, ST> Min<FT, ST>(Pair<FT, ST> p, Pair<FT, ST> q)
        where FT : IComparable<FT>
        where ST : IComparable<ST>
    { return (p.CompareTo(q) <= 0) ? p : q; }
    static public Pair<FT, ST> Max<FT, ST>(Pair<FT, ST> p, Pair<FT, ST> q)
        where FT : IComparable<FT>
        where ST : IComparable<ST>
    { return (p.CompareTo(q) >= 0) ? p : q; }
}
public struct Pair<FT, ST> : IComparable<Pair<FT, ST>>
    where FT : IComparable<FT>
    where ST : IComparable<ST>
{
    public FT x;
    public ST y;
    public Pair(FT f, ST s) : this() { x = f; y = s; }

    public int CompareTo(Pair<FT, ST> other)
    {
        var cmp = x.CompareTo(other.x);
        return cmp != 0 ? cmp : y.CompareTo(other.y);
    }
    public override string ToString() { return string.Format("{0} {1}", x, y); }
}
#endregion
#region AVLTree
public class AVLTree
{
    Node nil = new NilNode();
    Node root { get { return nil.lst; } }
    public AVLTree() { nil.lst = nil.rst = nil; }

    public int Count { get { return nil.lst.cnt; } }
    public long Value { get { return root.val; } }
    public void Add(long v) { Insert(v, LowerBound(v)); }
    public bool Remove(long v)
    {
        if (EqualRange(v) == 0) return false;
        RemoveAt(LowerBound(v));
        return true;
    }
    #region Impl
    public void Insert(long v, int k)
    {
        Node p = nil, t = nil.lst;
        if (t.cnt < k)
            throw new IndexOutOfRangeException();
        var isL = true;
        while (t != nil)
        {
            if (t.lst.cnt >= k) { p = t; t = t.lst; isL = true; }
            else { k -= (t.lst.cnt + 1); p = t; t = t.rst; isL = false; }
        }
        if (isL) { p.lst = CreateNode(v, p); Balance(true, p.lst); }
        else { p.rst = CreateNode(v, p); Balance(true, p.rst); }
    }
    public void RemoveAt(int k)
    {
        var t = nil.lst;
        while (t != nil)
        {
            if (t.lst.cnt > k) { t = t.lst; }
            else if (t.lst.cnt < k) { k -= t.lst.cnt + 1; t = t.rst; }
            else
            {
                if (t.lst == nil) { Node.Replace(t, t.rst); Balance(false, t.rst); }
                else
                {
                    var m = GetMaxNode(t.lst);
                    t.val = m.val;
                    Node.Replace(m, m.lst);
                    Balance(false, m.lst);
                }
                return;
            }
        }
    }
    public int EqualRange(long v) { return UpperBound(v) - LowerBound(v); }
    public int LowerBound(long v) { return lowerBound(nil.lst, v); }
    public int UpperBound(long v) { return upperBound(nil.lst, v); }
    public long this[int k] { get { return find(nil.lst, k); } }

    int lowerBound(Node t, long v)
    {
        if (t.cnt == 0) return 0;
        if (v <= t.val) return lowerBound(t.lst, v);
        else return t.lst.cnt + 1 + lowerBound(t.rst, v);
    }
    int upperBound(Node t, long v)
    {
        if (t.cnt == 0) return 0;
        if (t.val <= v) return t.lst.cnt + 1 + upperBound(t.rst, v);
        else return upperBound(t.lst, v);
    }
    long find(Node t, int k)
    {
        if (t.cnt <= k) throw new IndexOutOfRangeException();
        if (k == t.lst.cnt) return t.val;
        else if (k < t.lst.cnt) return find(t.lst, k);
        else return find(t.rst, k - (t.lst.cnt + 1));
    }
    #endregion
    class Node
    {
        int h;
        public int cnt;
        //public int Count { get { return cnt; } }
        public int Height { get { return h; } }
        public int Bias { get { return lst.Height - rst.Height; } }
        internal long val;
        internal Node par, lst, rst;
        internal bool rev;
        internal Node() { }
        internal Node(long v, Node p) { h = 1; cnt = 1; val = v; par = p; }
        public void Update()
        {
            h = 1 + Math.Max(lst.h, rst.h);
            cnt = 1 + lst.cnt + rst.cnt;
        }
        public override string ToString()
        {
            return string.Format("count:{0}, value:{1}", cnt, val);
        }

        #region Impl
        static internal void Replace(Node u, Node v)
        {
            var p = u.par;
            if (p.lst == u) p.lst = v;
            else p.rst = v;
            v.par = p;
        }
        static internal Node RotateL(Node v)
        {
            Node u = v.rst; Replace(v, u);
            v.rst = u.lst; u.lst.par = v;
            u.lst = v; v.par = u;
            v.Update();
            u.Update();
            return u;
        }
        static internal Node RotateR(Node u)
        {
            var v = u.lst; Replace(u, v);
            u.lst = v.rst; v.rst.par = u;
            v.rst = u; u.par = v;
            u.Update();
            v.Update();
            return v;
        }
        static internal Node RotateLR(Node t)
        {
            RotateL(t.lst);
            return RotateR(t);
        }
        static internal Node RotateRL(Node t)
        {
            RotateR(t.rst);
            return RotateL(t);
        }
        #endregion

    }
    class NilNode : Node { public override string ToString() { return "nil"; } }

    Node CreateNode() { return new Node() { lst = nil, rst = nil }; }
    Node CreateNode(long v, Node p) { return new Node(v, p) { lst = nil, rst = nil }; }

    void Balance(bool onInsert, Node t)
    {
        while (t.par != nil)
        {
            var u = t.par;
            var h = u.Height;
            if ((u.lst == t) == onInsert)
            {
                if (u.Bias == 2)
                {
                    if (u.lst.Bias >= 0) u = Node.RotateR(u);
                    else u = Node.RotateLR(u);
                }
                else u.Update();
            }
            else
            {
                if (u.Bias == -2)
                {
                    if (u.rst.Bias <= 0) u = Node.RotateL(u);
                    else u = Node.RotateRL(u);
                }
                else u.Update();
            }
            if (h == u.Height) break;
            t = u;
        }
        while (t.par != nil) { t.par.Update(); t = t.par; }
    }

    Node GetMaxNode(Node t)
    {
        while (t.rst != nil) t = t.rst;
        return t;
    }
}
#endregion


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace The_Two_Routes
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int m = Next();

            var nn = new List<int>[n];
            for (int i = 0; i < nn.Length; i++)
            {
                nn[i] = new List<int>();
            }
            for (int i = 0; i < m; i++)
            {
                int a = Next() - 1, b = Next() - 1;
                nn[a].Add(b);
                nn[b].Add(a);
            }

            var f = new int[n];
            Go(nn, f);

            if (f[n - 1] == 0)
            {
                writer.WriteLine("-1");
                writer.Flush();
                return;
            }

            int t1 = f[n - 1];
            for (int i = 0; i < nn.Length; i++)
            {
                nn[i].Sort();
                int index = 0;
                var tt = new List<int>();
                for (int j = 0; j < n; j++)
                {
                    while (index < nn[i].Count && nn[i][index] < j)
                        index++;
                    if (index >= nn[i].Count || nn[i][index] != j)
                    {
                        tt.Add(j);
                    }
                }
                nn[i] = tt;
            }
            f = new int[n];
            Go(nn, f);

            if (f[n - 1] == 0)
            {
                writer.WriteLine("-1");
                writer.Flush();
                return;
            }

            writer.WriteLine(Math.Max(t1, f[n - 1]) - 1);
            writer.Flush();
        }

        private static void Go(List<int>[] nn, int[] f)
        {
            var q = new Queue<int>();
            q.Enqueue(0);
            f[0] = 1;
            while (q.Count > 0)
            {
                int index = q.Dequeue();
                foreach (int i in nn[index])
                {
                    if (f[i] == 0)
                    {
                        q.Enqueue(i);
                        f[i] = f[index] + 1;
                    }
                }

                if (f[f.Length - 1] != 0)
                    break;
            }
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.IO;
using System.Text;

namespace Lipshitz_Sequence
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            int q = Next();

            var nn = new int[n];
            for (int i = 0; i < n; i++)
            {
                nn[i] = Next();
            }

            var mm = new int[n - 1];
            for (int i = 1; i < n; i++)
            {
                mm[i - 1] = Math.Abs(nn[i] - nn[i - 1]);
            }
            var left = new int[n - 1];
            left[0] = -1;
            for (int i = 1; i < mm.Length; i++)
            {
                int index = i - 1;
                while (index >= 0 && mm[index] < mm[i])
                {
                    index = left[index];
                }
                left[i] = index;
            }
            var rigth = new int[n - 1];
            rigth[n - 2] = n - 1;
            for (int i = n - 3; i >= 0; i--)
            {
                int index = i + 1;
                while (index < rigth.Length && mm[index] <= mm[i])
                {
                    index = rigth[index];
                }
                rigth[i] = index;
            }

            for (int i = 0; i < q; i++)
            {
                int l = Next() - 1, r = Next() - 1;

                long sum = 0;
                for (int j = l; j < r; j++)
                {
                    long d1 = Math.Min(r, rigth[j]) - j;
                    long d2 = j - Math.Max(l - 1, left[j]);
                    sum += mm[j]*d2*d1;
                }
                writer.WriteLine(sum);
            }

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    class SparseTable<T>
    {
        private const int MAX_LENGTH = 100000;
        private static int[] log = new int[MAX_LENGTH + 1];

        private readonly Comparison<T> comparison;
        private readonly int[,] table;
        private readonly T[] data;
        private readonly int length;
        private readonly int height;

        static SparseTable()
        {
            int c = 1;
            for (int i = 1; c <= MAX_LENGTH; i++)
                for (; c <= MAX_LENGTH && c < 1 << i; c++)
                    log[c] = i - 1;
        }

        public SparseTable(Comparison<T> comparison, T[] array)
        {
            this.comparison = comparison;
            data = array;
            length = array.Length;
            height = log[length] + 1;

            table = new int[length, height];
            for (int i = 0; i < length; i++)
                table[i, 0] = i;

            for (int i = 1; i < height; i++)
            {
                int bi = 1 << i;
                int pbi = 1 << i - 1;
                for (int j = 0; j + bi <= length; j++)
                {
                    int left = table[j, i - 1];
                    int right = table[j + pbi, i - 1];
                    if (comparison(data[left], data[right]) < 0)
                        table[j, i] = left;
                    else
                        table[j, i] = right;
                }
            }
        }

        public int Query(int l, int r)
        {
            int w = log[r - l + 1];
            int left = table[l, w];
            int right = table[r - (1 << w) + 1, w];
            if (comparison(data[left], data[right]) < 0)
                return left;
            return right;
        }
    }

    int[] a;
    SparseTable<int> table;
    long Fun(int l, int r)
    {
        int x = table.Query(l, r);
        long ret = 1L * a[x] * (x - l + 1) * (r - x + 1);
        if (x > l)
            ret += Fun(l, x - 1);
        if (x < r)
            ret += Fun(x + 1, r);
        return ret;
    }

    public void Solve()
    {
        int n = ReadInt() - 1;
        a = ReadIntArray();

        for (int i = 0; i < n; i++)
            a[i] = Math.Abs(a[i] - a[i + 1]);

        table = new SparseTable<int>((x, y) => y.CompareTo(x), a);
        for (int q = ReadInt(); q > 0; q--)
        {
            int l = ReadInt() - 1;
            int r = ReadInt() - 1;
            Write(Fun(l, r - 1));
        }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("atoms.in");
        //writer = new StreamWriter("atoms.out");
#endif
        try
        {
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
            new Solver().Solve();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
#if DEBUG
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0)currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++)matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++)ret[i][j] = matrix[j][i]; } return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++)lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array)writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++)ret[i] = new T(); return ret; }
    #endregion
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

data class Query(val id: Int, val l: Int, val r: Int)
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val Q = ni()
    val A = na(N)
    val query = Array(Q){Query(it, ni() - 1, ni() - 2)}

    val ans = LongArray(Q)
    val D = IntArray(N - 1) {
      abs(A[it] - A[it + 1])
    }
    val P = D.withIndex().sortedBy { -it.value }
    debug{P.joinToString(" ")}
    val pos = TreeSet<Int>()
    for (p in P) {
      val l = (pos.lower(p.index) ?: -1) + 1
      val r = (pos.higher(p.index) ?: N - 1) - 1
      for (q in query) {
        val vl = max(0, p.index - max(l, q.l) + 1)
        val vr = max(0, min(r, q.r) - p.index + 1)
        debug{"p=${p.index}:${p.value} id:${q.id} vl:$vl vr:$vr"}
        ans[q.id] += p.value.toLong() * vl * vr
      }
      pos += p.index
    }

    for (i in ans) {
      out.println(i)
    }
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AlexFetisov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB_Cool_But_Hard_To_Think solver = new TaskB_Cool_But_Hard_To_Think();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB_Cool_But_Hard_To_Think {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int countQueries = in.nextInt();
            int[] a = Utils.readIntArray(in, n);
            long[] L = new long[n - 1];
            for (int i = 1; i < n; ++i) {
                L[i - 1] = Math.abs(a[i] - a[i - 1]);
            }
            --n;
            int[] left = new int[n];
            int[] right = new int[n];
            List<Integer> stack = new ArrayList<Integer>();
            for (int i = 0; i < n; ++i) {
                while (!stack.isEmpty()) {
                    if (L[i] >= L[stack.get(stack.size() - 1)]) {
                        stack.remove(stack.size() - 1);
                    } else {
                        break;
                    }
                }
                if (!stack.isEmpty()) {
                    left[i] = stack.get(stack.size() - 1);
                } else {
                    left[i] = -1;
                }
                stack.add(i);
            }

            stack.clear();
            for (int i = n - 1; i >= 0; --i) {
                while (!stack.isEmpty()) {
                    if (L[i] > L[stack.get(stack.size() - 1)]) {
                        stack.remove(stack.size() - 1);
                    } else {
                        break;
                    }
                }
                if (!stack.isEmpty()) {
                    right[i] = stack.get(stack.size() - 1);
                } else {
                    right[i] = n;
                }
                stack.add(i);
            }

            while (countQueries-- > 0) {
                int le = in.nextInt() - 1;
                int ri = in.nextInt() - 1;
                long res = 0;
                for (int i = le; i < ri; ++i) {
                    int leftId = Math.max(le, left[i] + 1);
                    int rightId = Math.min(right[i], ri);

                    res += L[i] * (i - leftId + 1) * (rightId - i);
                }
                out.println(res);
            }

        }

    }

    static class Utils {
        public static int[] readIntArray(InputReader in, int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            return a;
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String nextString() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
 import java.util.*;
public  class realfast implements Runnable
  {
    private static final int INF = (int) 1e9;
    long in= 998244353;
    long fac[]= new long[3000];
    public  void solve() throws IOException
    {
      int n = readInt();
      int q = readInt();
      int arr[]= new int[n+1];

      for(int i=1;i<=n;i++)
        arr[i]=readInt();

      int mat[]= new int[n];

      for(int i=1;i<n;i++)
      {
        mat[i]=Math.abs(arr[i]-arr[i+1]);
      }

      int next[]= new int[n];
      int prev[]= new int[n];
      Arrays.fill(prev,0);
      Arrays.fill(next,n);
      int stack[]= new int[n+10];
      int top=-1;
      for(int i=1;i<n;i++)
      {
        //System.out.println(i+" "+top);
        if(top==-1)
        {
            top++;
            stack[top]=i;

        }
        else
        {

            while((top>-1)&&(mat[stack[top]]<mat[i]))
            {
               // out.println(mat[i]+"      "+mat[stack[top]]);
                  next[stack[top]]=i;
                  top--;
            }
            top++;
            stack[top]=i;
        }
      }
      //out.println();

      top=-1;

      for(int i=n-1;i>=1;i--)
      {
        if(top==-1)
        {
            top++;
            stack[top]=i;
        }
        else
        {
            while(top>-1&&mat[stack[top]]<=mat[i])
            {
                  prev[stack[top]]=i;
                  top--;
            }
            top++;
            stack[top]=i;
        }
      }

     // int q = readInt();

      for(int f =0;f<q;f++)
      {
        int l = readInt();
        int r = readInt();
        long val =0;

        for(int i =l;i<r;i++)
        {
            int c1 = Math.max(l-1,prev[i]);
            int c2 = Math.min(r,next[i]);
            long val1 = i-c1;
            val1 = val1*(c2-i);
            val1 = val1*(mat[i]);
            val = val + val1;
        }
        out.println(val);
      }

    }

    public int build(int seg[] , int left, int right , int index , int sum[])
    {
             if(left==right)
             {
                seg[index]= sum[left];
                return seg[index];
             }
             int mid = left +(right-left)/2;
             int left1 = build(seg, left,mid,2*index+1,sum);
             int right1 = build(seg,mid+1,right, 2*index+2,sum);
             seg[index]=Math.max(left1,right1);
             return seg[index];
    }
    public int value (int seg[], int left , int right ,int index, int l, int r)
    {

            if(left>right)
            {
              return -100000000;
            }
            if(right<l||left>r)
                return -100000000;
            if(left>=l&&right<=r)
                return seg[index];
            int mid = left+(right-left)/2;
            int val = value(seg,left,mid,2*index+1,l,r);
            int val2 = value(seg,mid+1,right,2*index+2,l,r);
            return Math.max(val,val2);

    }

    public int gcd(int a , int b )
    {
      if(a<b)
      {
        int t =a;
        a=b;
        b=t;
      }
      if(a%b==0)
        return b ;
      return gcd(b,a%b);
    }
    public long pow(long n , long p,long m)
    {
         if(p==0)
            return 1;
        long val = pow(n,p/2,m);;
        val= (val*val)%m;
        if(p%2==0)
            return val;
        else
            return (val*n)%m;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
    }

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;

    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }

    private String readString() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class edge implements Comparable<edge>{
    int val ;
    int color;

    edge(int u, int v)
    {
       this.val=u;
       this.color=v;
    }
    public int compareTo(edge e)
    {
        return this.val-e.val;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class LipshitzSequence
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++)
			arr[i] = sc.nextInt();
		for (int i = 0; i < q; i++)
		{
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;
			int[] diff = new int[r-l];
			int ind = 0;
			for (int j = l+1; j <= r; j++)
				diff[ind++] = Math.abs(arr[j] - arr[j-1]);
			int[] left = new int[r-l];
			int[] right = new int[r-l];
			Stack<Integer> st = new Stack<Integer>();
			ind = 0;
			for (int j = l; j < r; j++)
			{
				while(!st.isEmpty() && diff[st.peek()]<diff[j-l])
					st.pop();
				if(st.isEmpty())
					left[ind++] = -1;
				else
					left[ind++] = st.peek();
				st.push(j-l);
			}

			st = new Stack<Integer>();
			ind = right.length-1;
			for (int j = r-1; j >= l; j--)
			{
				while(!st.isEmpty() && diff[st.peek()]<=diff[j-l])
					st.pop();
				if(st.isEmpty())
					right[ind--] = r-l;
				else
					right[ind--] = st.peek();
				st.push(j-l);
			}

			long ans = 0;
			for (int j = l; j < r; j++)
				ans += 1l*diff[j-l]*(((right[j-l] - (j-l))*((j-l) - left[j-l])));
			pw.println(ans);
		}
		pw.flush();
		pw.close();
	}
	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class LipshitzSequence
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++)
			arr[i] = sc.nextInt();

		int[] diff = new int[n-1];
		for (int j = 1; j < n; j++)
			diff[j-1] = Math.abs(arr[j] - arr[j-1]);
		int[] left = new int[n-1];
		int[] right = new int[n-1];

		Stack<Integer> st = new Stack<Integer>();
		for (int j = 0; j < n-1; j++)
		{
			while(!st.isEmpty() && diff[st.peek()]<diff[j])
				st.pop();
			if(st.isEmpty())
				left[j] = -1;
			else
				left[j] = st.peek();
			st.push(j);
		}

		st = new Stack<Integer>();
		for (int j = n-2; j >= 0; j--)
		{
			while(!st.isEmpty() && diff[st.peek()]<=diff[j])
				st.pop();
			if(st.isEmpty())
				right[j] = n-1;
			else
				right[j] = st.peek();
			st.push(j);
		}

		for (int i = 0; i < q; i++)
		{
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;

			long ans = 0;
			r--;
			for (int j = l; j <= r; j++)
				ans += 1l*diff[j]* (j - Math.max(left[j], l-1)) * (Math.min(right[j], r+1) - j);
			pw.println(ans);
		}
		pw.flush();
		pw.close();
	}
	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
import java.util.StringTokenizer;

public class LipshitzSequence
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt();
		int q = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < arr.length; i++)
			arr[i] = sc.nextInt();

		int[] diff = new int[n-1];
		for (int j = 1; j < n; j++)
			diff[j-1] = Math.abs(arr[j] - arr[j-1]);
		int[] left = new int[n-1];
		int[] right = new int[n-1];

		Stack<Integer> st = new Stack<Integer>();
		for (int j = 0; j < n-1; j++)
		{
			while(!st.isEmpty() && diff[st.peek()]<diff[j])
				st.pop();
			if(st.isEmpty())
				left[j] = -1;
			else
				left[j] = st.peek();
			st.push(j);
		}

		st = new Stack<Integer>();
		for (int j = n-2; j >= 0; j--)
		{
			while(!st.isEmpty() && diff[st.peek()]<=diff[j])
				st.pop();
			if(st.isEmpty())
				right[j] = n-1;
			else
				right[j] = st.peek();
			st.push(j);
		}

		for (int i = 0; i < q; i++)
		{
			int l = sc.nextInt()-1;
			int r = sc.nextInt()-1;

			long ans = 0;
			for (int j = l; j < r; j++)
				ans += 1l*diff[j]*(Math.min(right[j], r) - (j))*((j) - Math.max(l-1, left[j]));
			pw.println(ans);
		}
		pw.flush();
		pw.close();
	}
	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}
	}
}