Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$.

Polycarp considers the price on the day $i$ to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if $n=6$ and $a=[3, 9, 4, 6, 7, 5]$, then the number of days with a bad price is $3$ — these are days $2$ ($a_2=9$), $4$ ($a_4=6$) and $5$ ($a_5=7$).

Print the number of days with a bad price.

You have to answer $t$ independent data sets.


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of sets of input data in the test. Input data sets must be processed independently, one after another.

Each input data set consists of two lines. The first line contains an integer $n$ ($1 \le n \le 150000$) — the number of days. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$), where $a_i$ is the price on the $i$-th day.

It is guaranteed that the sum of $n$ over all data sets in the test does not exceed $150000$.


-----Output-----

Print $t$ integers, the $j$-th of which should be equal to the number of days with a bad price in the $j$-th input data set.


-----Example-----
Input
5
6
3 9 4 6 7 5
1
1000000
2
2 1
10
31 41 59 26 53 58 97 93 23 84
7
3 2 1 2 3 4 5

Output
3
0
1
8
2

Difficulty: introductory

Starter code:

Solutions:
for _ in range(int(input())):
    n = int(input())
    A = list(map(int, input().split()))
    m = 10 ** 9
    c = 0
    for i in range(n - 1, -1, -1):
        if A[i] <= m:
            m = A[i]
        else:
            c += 1
    print(c)

t = int(input())
for z in range(t):
    n = int(input())
    arr = list(map(int, input().split()))
    cnt = 0
    mn = arr[-1]
    for i in range(n - 1, -1, -1):
        cnt += arr[i] > mn
        mn = min(arr[i], mn)
    print(cnt)

for _ in range(int(input())):
    n=int(input())
    l1=list(map(int,input().split()))
    m=l1[-1]
    ans=0
    for i in range(-2,-n-1,-1):
        if l1[i]>m:
            ans+=1
        else :
            m=l1[i]
    print(ans)

t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    mn = 10 ** 9
    ans = 0
    for x in reversed(a):
        if x > mn:
            ans += 1
        mn = min(mn, x)
    print(ans)

# Contest: Codeforces Round #582 (Div. 3) (https://codeforces.com/contest/1213)
# Problem: B: Bad Prices (https://codeforces.com/contest/1213/problem/B)

def rint():
    return int(input())


def rints():
    return list(map(int, input().split()))


t = rint()
for _ in range(t):
    n = rint()
    a = rints()
    mi = a[-1]
    bad = 0
    for ai in reversed(a[:-1]):
        if ai > mi:
            bad += 1
        mi = min(mi, ai)
    print(bad)


t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    mi=10000000
    ans=0
    i=n-1
    while (i>=0):
        if a[i]>mi:
            ans+=1
        if a[i]<mi:
            mi=a[i]
        i-=1
    print(ans)

def inp(): return int(input())
def ln(): return [int(x) for x in input().split()]

def solve():
    n = inp()
    a = ln()
    mns = [-1]*n
    mns[-1] = a[-1]
    for i in range(n-2,-1,-1):
        mns[i] = min(a[i], mns[i+1])

    cnt = 0
    for i in range(n):
        if i + 1 < n and mns[i+1] < a[i]:
            cnt += 1
    print(cnt)

for _ in range(inp()):
    solve()


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s_min = [10 ** 9] * n
    s_min[-1] = a[-1]
    for i in range(n - 2, -1, -1):
        s_min[i] = min(s_min[i + 1], a[i])
    cnt = 0
    for i in range(n - 1):
        cnt += (s_min[i + 1] < a[i])
    print(cnt)

t = int(input())
while t:
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    minn = a[0]
    ans = 0
    for i in range(1, n):
        if a[i] > minn:
            ans += 1
        minn = min(minn, a[i])
    print(ans)
    t -= 1

def mi():
        return list(map(int, input().split()))
'''
5
6
3 9 4 6 7 5
1
1000000
2
2 1
10
31 41 59 26 53 58 97 93 23 84
7
3 2 1 2 3 4 5
'''
for _ in range(int(input())):
    n = int(input())
    a = list(mi())[::-1]
    m = a[0]
    ans = 0
    for i in range(n):
        if a[i]>m:
            ans+=1
        elif a[i]<m:
            m = a[i]
    print (ans)


from sys import stdin
t=int(stdin.readline().strip())
for j in range(t):
    n=int(stdin.readline().strip())
    s=list(map(int,stdin.readline().strip().split()))
    mn=s[-1]
    ans=0
    for i in range(n-2,-1,-1):
        if mn<s[i]:
            ans+=1
        mn=min(mn,s[i])
    print(ans)
        
            
    


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    ans, min1 = 0, float('inf')
    for q in range(n-1, -1, -1):
        if a[q] > min1:
            ans += 1
        min1 = min(min1, a[q])
    print(ans)


#double underscore makes a class variable or a class method private
mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
it = lambda : tuple(map(int, input().split()))
ls = lambda : list(input())
t=ii()
for _ in range(t):
    n=ii()
    l=il()
    mn=l[-1]
    c=0
    for i in range(n-1,-1,-1):
        if l[i]>mn:
            c+=1
        mn=min(mn,l[i])
    print(c)

import math
tst = int(input())
for i in range(tst):
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    mn = a[0] + 100
    cnt = 0
    for c in a:
        if mn < c:
            cnt += 1
        mn = min(mn, c)
    print(cnt)



from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10**5+10
MOD = 10**9+7
def isprime(n):
    n = abs(int(n))
    if n < 2:
        return False
    if n == 2: 
        return True    
    if not n & 1: 
        return False
    for x in range(3, int(n**0.5) + 1, 2):
        if n % x == 0:
            return False
    return True

def mhd(a,b):
    return abs(a[0]-b[0])+abs(b[1]-a[1])

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def eld(x,y):
    a = y[0]-x[0]
    b = x[1]-y[1]
    return (a*a+b*b)**0.5

def lgcd(a):
    g = a[0]
    for i in range(1,len(a)):
        g = math.gcd(g,a[i])
    return g

def ms(a):
    msf = -MAX
    meh = 0
    st = en = be = 0
    for i in range(len(a)):
        meh+=a[i]
        if msf<meh:
            msf = meh
            st = be
            en = i
        if meh<0:
            meh = 0
            be = i+1
    return msf,st,en

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD



def flush():
    return sys.stdout.flush()


def fac(n):
    ans = 1
    for i in range(1,n+1):
        ans*=i
        ans%=MOD
    return ans

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
for _ in range(int(input())):
    n = int(input())
    a = arrIN()
    x = [MAX]*(n)
    x[-1] = a[-1]
    for i in range(n-2,-1,-1):
        x[i] = min(x[i+1],a[i])
    ans = 0
    for i in range(n-1):
        if x[i+1]<a[i]:
            ans+=1
    print(ans)


# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!!
from sys import stdin, stdout
from collections import defaultdict
from collections import deque
import math
import copy
 
T = int(input())
#N = int(input())
#s1 = input()
#s2 = input()
#N,Q = [int(x) for x in stdin.readline().split()]
#arr = [int(x) for x in stdin.readline().split()]

for i in range(T):
    N = int(input())
    arr = [int(x) for x in stdin.readline().split()]
    
    mini = [0]*N
    
    m = arr[-1]
    
    for i in range(N-1,-1,-1):
        m = min(m,arr[i])
        mini[i] = m
        
    res = 0
    for i in range(N-1):
        if arr[i]>mini[i+1]:
            res += 1
            
    print(res)

Q = int(input())
for q in range(Q):
    n = int(input())
    arr = list(map(int, input().split()))

    minimal = 1e9
    bad = 0
    for i in arr[::-1]:
        if i < minimal:
            minimal = i
        if i > minimal:
            bad += 1

    print(bad)


t = int(input())
for _ in range(t):
    n = int(input())

    a = list(map(int, input().split()))
    m = a[-1]
    res = 0
    
    for i in range(n-1, -1, -1):
        if a[i] > m:
            res += 1
        m = min(m, a[i])

    print(res)




t = int(input())
for i in range(t):
    n = int(input())
    c = 0
    data = list(map(int, input().split()))
    stack = []
    for i in data:
        if not stack:
            stack.append(i)
        else:
            while stack and stack[-1] > i:
                c += 1
                stack.pop()
            stack.append(i)
    print(c)

def int_multiple():
    return  [int(c) for c in input().split()]

def int_single():
    return int(input())

def str_multiple():
    return [c for c in input().split()]

def str_single():
    return input()

# start
t = int_single()

res = []

for i in range(t):
    n = int_single()
    l = int_multiple()
    cnt = 0
    mn = l[-1]
    for j in reversed(list(range(n))):
        if l[j] < mn:
            mn = l[j]
        if l[j] > mn:
            cnt += 1

    res.append(cnt)

for r in res:
    print(r)


t = int(input())
while t > 0:
    n = int(input())
    arr = [int(x) for x in input().split()]
    low = arr[n-1]
    bad = 0
    for i in range(n-2, -1, -1):
        if arr[i] > low: bad += 1
        low = min(low, arr[i])
    print(bad)
    t -= 1

import sys
mod = 1000000007
def get_array(): return list(map(int, sys.stdin.readline().split()))
def get_ints(): return map(int, sys.stdin.readline().split())
def input(): return sys.stdin.readline()
def print_array(a): print(" ".join(map(str, a)))
def main():
        for _ in range(int(input())):
                n = int(input())
                a = get_array()
                m = a[n - 1]
                cnt = 0
                for i in range(n - 2, -1, -1):
                        if a[i] > m: cnt += 1
                        if a[i] < m : m = a[i]
                print(cnt)
def __starting_point():
        main()
__starting_point()

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    b = [-1]*n
    b[n-1] = a[n-1]
    ans = 0
    for i in range(n-2, -1, -1):
        b[i] = min(b[i+1], a[i])
    for i in range(n-1):
        if(a[i] > b[i]):
            ans += 1
    print(ans)


T = int(input())
for i in range(T):
	N = int(input())
	l = [int(x) for x in input().split()]
	ans = 0
	s = l[-1]
	for j in reversed(l):
		if(j > s): ans += 1
		else: s = j
	print(ans)