#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int t;
  scanf("%d", &t);
  int a;
  for (a = 0; a < t; a++) {
    int n;
    scanf("%d", &n);
    int i;
    long long int x, count = 1, ans = 0, prev;
    scanf("%lld", &prev);
    for (i = 1; i < n; i++) {
      scanf("%lld", &x);
      if (x >= prev) {
        count++;
      } else {
        ans += count * (count + 1) / 2;
        count = 1;
      }
      prev = x;
    }
    ans += count * (count + 1) / 2;
    printf("%lld\n", ans);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    124c <main+0x12c>
lea    0xea5(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movq   $0x1,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe86(%rip),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    120c <main+0xec>
lea    0xe61(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x20(%rbp),%rax
cmp    -0x38(%rbp),%rax
jl     11cc <main+0xac>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11f6 <main+0xd6>
mov    -0x28(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
imul   %rcx,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x1,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118f <main+0x6f>
mov    -0x28(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    $0x1,%rcx
imul   %rcx,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xdcf(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1148 <main+0x28>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    122e <main+0x10e>
lea    0xeb0(%rip),%rbx
lea    0x10(%rsp),%r13
xor    %r14d,%r14d
jmp    119b <main+0x7b>
nopl   (%rax)
mov    $0x1,%eax
xor    %r15d,%r15d
lea    0x1(%rax),%rcx
imul   %rax,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
add    %rcx,%rsi
sar    %rsi
add    %r15,%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
jge    122e <main+0x10e>
lea    0xe5e(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x2,(%rsp)
jl     1160 <main+0x40>
mov    $0x1,%r12d
mov    $0x1,%ebp
xor    %r15d,%r15d
jmp    11f6 <main+0xd6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rcx,0x8(%rsp)
add    $0x1,%r12d
mov    %rax,%rbp
cmp    (%rsp),%r12d
jge    1168 <main+0x48>
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x10(%rsp),%rcx
lea    0x1(%rbp),%rax
cmp    0x8(%rsp),%rcx
jge    11e0 <main+0xc0>
imul   %rbp,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
add    %rax,%rdx
sar    %rdx
add    %rdx,%r15
mov    $0x1,%eax
jmp    11e0 <main+0xc0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %11
11: ; preds = %53, %0
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %56
15: ; preds = %11
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
store i64 1, i64* %7
store i64 0, i64* %8
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %9)
store i32 1, i32* %5
br label %18
18: ; preds = %40, %15
%19 = load i32, i32* %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %6)
%24 = load i64, i64* %6
%25 = load i64, i64* %9
%26 = icmp sge i64 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i64, i64* %7
%29 = add nsw i64 %28, 1
store i64 %29, i64* %7
br label %38
30: ; preds = %22
%31 = load i64, i64* %7
%32 = load i64, i64* %7
%33 = add nsw i64 %32, 1
%34 = mul nsw i64 %31, %33
%35 = sdiv i64 %34, 2
%36 = load i64, i64* %8
%37 = add nsw i64 %36, %35
store i64 %37, i64* %8
store i64 1, i64* %7
br label %38
38: ; preds = %30, %27
%39 = load i64, i64* %6
store i64 %39, i64* %9
br label %40
40: ; preds = %38
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %18
43: ; preds = %18
%44 = load i64, i64* %7
%45 = load i64, i64* %7
%46 = add nsw i64 %45, 1
%47 = mul nsw i64 %44, %46
%48 = sdiv i64 %47, 2
%49 = load i64, i64* %8
%50 = add nsw i64 %49, %48
store i64 %50, i64* %8
%51 = load i64, i64* %8
%52 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %51)
br label %53
53: ; preds = %43
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %11
56: ; preds = %11
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%lld\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i32* %1 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %49
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = bitcast i64* %3 to i8*
%12 = bitcast i64* %4 to i8*
br label %13
13: ; preds = %9, %38
%14 = phi i32 [ 0, %9 ], [ %46, %38 ]
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %4)
%17 = load i32, i32* %2
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %38
19: ; preds = %13, %32
%20 = phi i64 [ %34, %32 ], [ 0, %13 ]
%21 = phi i64 [ %33, %32 ], [ 1, %13 ]
%22 = phi i32 [ %35, %32 ], [ 1, %13 ]
%23 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%24 = load i64, i64* %3
%25 = load i64, i64* %4
%26 = icmp slt i64 %24, %25
%27 = add nsw i64 %21, 1
br i1 %26, label %28, label %32
28: ; preds = %19
%29 = mul nsw i64 %27, %21
%30 = sdiv i64 %29, 2
%31 = add nsw i64 %30, %20
br label %32
32: ; preds = %19, %28
%33 = phi i64 [ 1, %28 ], [ %27, %19 ]
%34 = phi i64 [ %31, %28 ], [ %20, %19 ]
store i64 %24, i64* %4
%35 = add nuw nsw i32 %22, 1
%36 = load i32, i32* %2
%37 = icmp slt i32 %35, %36
br i1 %37, label %19, label %38
38: ; preds = %32, %13
%39 = phi i64 [ 1, %13 ], [ %33, %32 ]
%40 = phi i64 [ 0, %13 ], [ %34, %32 ]
%41 = add nsw i64 %39, 1
%42 = mul nsw i64 %41, %39
%43 = sdiv i64 %42, 2
%44 = add nsw i64 %43, %40
%45 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %44)
%46 = add nuw nsw i32 %14, 1
%47 = load i32, i32* %1
%48 = icmp slt i32 %46, %47
br i1 %48, label %13, label %49
49: ; preds = %38, %0
ret i32 0
}