#P9147. DOS Card

DOS Card

Source: Super League of Chinese College Students Algorithm Design 2022, Contest 2 by HDU.

Problem Description

DOS is a new single-player game that Kayzin came up with. At the beginning of the game you will be given n cards in a row, each with the number of value aia_i.

In each "matching" operation you can choose any two cards (we assume that the subscripts of these two cards are i,j(i<j)i,j (i < j). Notice that ii is less than jj), and you will get a score of (ai+aj)×(aiaj)(a_i+a_j)\times (a_i-a_j).

Kayzin will ask you mm times. In the k-th query, you need to select four cards from the cards with subscripts LkL_k to RkR_k, and "match" these four cards into two pairs (i.e., two matching operations, but the subscripts of the cards selected in the two matching operations must be different from each other. That is, a card can only be matched at most once. e.g., if you select four tickets with subscripts aa, bb, cc, and dd, matching aa with bb and cc with dd, or matching aa with cc and bb with dd are legal, but matching aa with bb and bb with cc is not legal), please calculate the maximum value of the sum of the two matching scores.

Note that the queries are independent of each other.

Input

The first line contains an integer T(T100)T(T\le 100) . Then TT test cases follow. For one case,

The first line contains two integer nn (4n2×105)(4\le n\le 2\times 10^5) and mm (1m105)(1\le m\le 10^5) , nn denotes the total number of cards , mm denotes the number of times Kayzin queries.

The second line contains nn integers a1,a2,,ana_1,a_2,…,a_n (1ai108)(1\le a_i\le 10^8), denotes the value of each card.

The next mm lines contain Kayzin's queries. The kkth line has two numbers, LkL_k and RkR_k (1LkRkn)(1\le L_k\le R_k\le n), the input guarantees that RkLk3R_k-L_k\ge 3.

It is guaranteed that the sum of nn over all test cases doesn't exceed 2×1052\times 10^5 and the sum of mm over all test cases doesn't exceed 2×1052\times 10^5.

Output

Print mm integer for each case, indicating the maximum scores that can be obtained by selecting four cards (two matching pairs).

Sample

1
5 3
5 3 2 8 4
1 5
1 4
2 5
69
-34
53