line = await readline() let total = +line let res = [] while (total--) { line = await readline() let days = +line line = await readline() let nums = line.split(' ').map(Number) let count = 0 let max = -Infinity let sorted = [] for (let i = 0; i < nums.length; i++) { let index = sorted.indexOf(nums[i]) if (index == -1) { sorted.push(nums[i]) if (sorted.length == 1) { max = count continue } let j = sorted.length - 1 for (; j > 0; j--) { if (sorted[j] < sorted[j - 1]) { [sorted[j], sorted[j - 1]] = [sorted[j - 1], sorted[j]]; } else { break } } count = count + j - (sorted.length - 1 - j) } else { count = count + index - (sorted.length - 1 - index) } if (count > max) { max = count } } let str = max + ' ' + count res.push(str) } res.forEach((item) => console.log(item))