#include<bits/stdc++.h> usingnamespace std; intmain(){ int tt; cin >> tt; while (tt--) { int n, m; cin >> n >> m; longlong ans = 0; ans += 1LL * (1 + m) * m / 2; ans += 1LL * (m + n * m) * n / 2; cout << ans - m << endl; } return0; }
#ifdef LOCAL #include"algo/debug.h" #else #define debug(...) 42 #endif
#define rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, a, n) for (int i = n; i >= a; i--) #define max(a, b) (a > b ? a : b) #define min(a, b) (a < b ? a : b) #define mp make_pair #define pb push_back #define fi first #define se second #define pi acos(-1) #define il inline #define rg register #define SZ(x) ((int)(x).size()) #define all(x) x.begin(), x.end() #define INF 0x7fffffff; #define inf 0x3f3f3f3f; #define MOD 998244353; #define mod 1000000007; typedef vector<int> VI; typedef pair<int, int> PII; typedeflonglong ll; typedefdouble db; ll gcd(ll a, ll b){ return b ? gcd(b, a % b) : a; }
intmain(){ int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<ll> a(n + 1, 0); rep(i, 1, n) cin >> a[i]; ll R = 0; ll ans = 0; for (int i = 1; i < n; i++) { a[i + 1] -= R; ans += abs(a[i] - a[i + 1]); if (a[i] < a[i + 1]) R += a[i + 1] - a[i], a[i + 1] = a[i]; } // cout << ans << endl; // ans += abs(a[n - 1] - a[n]); ans += abs(a[n]); cout << ans << endl; } return0; }