#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #define Cpp11 #ifdef Cpp11 #include #include #include #include #include #include #include #include #include #include #include using namespace std::chrono; #endif using namespace std; typedef double ld; typedef long long ll; typedef unsigned long long ull; typedef vector vi; typedef vector vvi; typedef pair pii; const int mx[4] = { 1, 0, -1, 0 }; const int my[4] = { 0, 1, 0, -1 }; const int Inf = 1000000000; const int MOD = 1000000007; const int N = 100005; const int K = 30; const ld eps = 10e-8; const ld PI = 2 * acos(0.0); const ll InfLL = ll(Inf) * ll(Inf); unsigned rand16() { return rand() % (1 << 16); } unsigned rand32() { return (rand16() << 16) + rand16(); } ull rand64() { return (((ull)rand32()) << 32) + rand32(); } int rand(int L, int R) { if (L > R) return R; return rand32() % (R - L + 1) + L; } ld random(ld L, ld R) { return rand(ceil((L - eps) * 100), floor((R + eps) * 100)) / 100.0; } ll Abs(ll a) { return a < 0 ? -a : a; } ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); } string toStr(int n) { char s[100]; sprintf(s, "%d", n); return string(s); } const int MAXN = 1000000; const int MAXT = 1000000; const int SUMN = 1000000; const int MAXM = 1000000000; #define ONLINE_JUDGE int main() { std::ios_base::sync_with_stdio(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T; scanf("%d", &T); assert(T > 0 && T <= MAXT); ll sumn = 0; for (int t = 0; t < T; ++t) { int n; scanf("%d", &n); sumn += n; assert(n > 0 && n <= MAXN); int prev; scanf("%d", &prev); assert(prev > 0 && prev <= MAXM); ll ans = prev; for (int i = 1; i < n; ++i) { int cur; scanf("%d", &cur); assert(cur > 0 && cur <= MAXM); if (cur > prev) ans += cur - prev; prev = cur; } printf("%lld\n", ans); } assert(sumn > 0 && sumn <= SUMN); return 0; }