//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define mp make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n,arr[200001];
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        //sort(arr,arr+n);
        /*LL sum=0;
        for(int i=0;i<n-1;i++)
        {
            sum+=abs(arr[i]-arr[i+1]);
        }
        cout<<sum<<endl;*/
        cout<<(n*(n-1)/2)<<endl;
    }
}


//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define mp make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n,arr[200001];
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        sort(arr,arr+n);
        LL sum=0;
        for(int i=0;i<n-1;i++)
        {
            sum+=(arr[n-1]-arr[i]);
        }
        cout<<sum<<endl;
    }
}


//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define mp make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n,arr[200001],a;
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
        {
            cin>>a;
            arr[a]=i;
        }
        //sort(arr,arr+n);
        LL sum=0;
        for(int i=2;i<=n;i++)
        {
            sum+=abs(arr[i]-arr[i-1]);
        }
        cout<<sum<<endl;

    }
}


//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define mp make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n,arr[200001];
    while(cin>>n)
    {
        for(int i=1;i<=n;i++)
        {
            cin>>arr[i];
        }
        //sort(arr,arr+n);
        LL sum=0;
        for(int i=2;i<=n;i++)
        {
            sum+=abs(arr[i]-arr[i-1]);
        }
        cout<<sum<<endl;

    }
}


#include <bits/stdc++.h>

using namespace std;

const int MaxN=2E5+10;
int a[MaxN];

int main(){
	int n;
	cin >> n;
	for (int i=0;i<n;++i){
		int x;
		cin >> x;
		--x;
		a[x]=i;
	}
	long long ans=0;
	for (int i=1;i<n;++i)
		ans+=abs(a[i]-a[i-1]);
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int MaxN=1E5+10;
int a[MaxN];

int main(){
	int n;
	cin >> n;
	for (int i=0;i<n;++i){
		int x;
		cin >> x;
		--x;
		a[x]=i;
	}
	long long ans=0;
	for (int i=1;i<n;++i)
		ans+=abs(a[i]-a[i-1]);
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int MaxN=1E5+10;
int a[MaxN];

int main(){
	int n;
	cin >> n;
	for (int i=0;i<n;++i){
		int x;
		cin >> x;
		a[x]=i;
	}
	long long ans=0;
	for (int i=1;i<n;++i)
		ans+=abs(a[i]-a[i-1]);
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main(){
	int n;
	cin >> n;
	cout << n*(n-1)/2;
}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    int f[20005], pos[20005];
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> f[i];
        pos[f[i]] = i;
    }
    int ans = 0;
    for(int i = 2; i <= n; i++)
        ans += abs(pos[i] - pos[i-1]);
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    int f[200005], pos[200005];
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> f[i];
        pos[f[i]] = i;
    }
    int ans = 0;
    for(int i = 2; i <= n; i++)
        ans += abs(pos[i] - pos[i-1]);
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    int f[200005], pos[200005];
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> f[i];
        pos[f[i]] = i;
    }
    long long ans = 0;
    for(int i = 2; i <= n; i++)
        ans += abs(pos[i] - pos[i-1]);
    cout << ans << endl;
    return 0;
}


#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int n;
    int f[10005], pos[10005];
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> f[i];
        pos[f[i]] = i;
    }
    int ans = 0;
    for(int i = 2; i <= n; i++)
        ans += abs(pos[i] - pos[i-1]);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        int a[n+1],b[n+1];
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            b[a[i]]=i;
        }
        long long int sum=0;
        for(int i=1;i<n;i++)
        {
            sum+=abs(b[i+1]-b[i]);
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
struct data
{
    int num;//记录下标
    int x;//记录数值
}Data[200010];

bool compare(data A,data B)
{
    return B.x>A.x;
}

int main()
{
    int i,n;
    cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>Data[i].x;
        Data[i].num=i;
    }

    sort(Data,Data+n,compare);

    long long sum=0;
    for(i=0;i<n-1;i++)
        sum+=abs(Data[i+1].num-Data[i].num);
    cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long long  n,i;
    while (cin>>n)
    {
        long long  total=0;
        long long  six[n],sixshadow[n];
        for (i=0; i<n; i++)
        {
            cin>>six[i];
            sixshadow[six[i]-1]=i;
        }
        for(i=0;i<n-1;i++)
        {
            total+=abs(sixshadow[i]-sixshadow[i+1]);
        }
        cout<<total<<endl;
    }
    return 0;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cstring>
#define pi 3.1415926
using namespace std;
int main()
{
    int n;
    while(cin>>n){
        int a[200100],i=0;
        int k,ans=0;
        for(i=1;i<=n;i++){
            cin>>k;
            a[k]=i;
        }
        for(i=2;i<=n;i++){
            ans+=abs(a[i]-a[i-1]);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
map<int, int>ma;
long long res;
int n,x;
int main(){
    res=0;
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&x);
        ma[x]=i;
    }
    for (int i=1,j=2; j<=n; i++,j++) {
        res+=(long long)abs(ma[j]-ma[i]);
    }
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
struct Element
{ long x, p; };
long n; Element f[2*MAXN+5];
bool compare(Element a, Element b)
{ return (a.x < b.x); }
void Solve()
{
	long long c = 0;
	for (long i = 1; i < n; ++i)
		c += abs(f[i].p - f[i + 1].p);
	cout << c;
}
int main()
{
    ios_base::sync_with_stdio();
    cin >> n;
    for (long i = 1; i <= n; ++i)
	{
		cin >> f[i].x;
		f[i].p = i;
	}
	sort(f + 1, f + n + 1, compare);
	Solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
long n, f[2*MAXN+5], x;
void Solve()
{
	long long c = 0;
	for (long i = 1; i < n; ++i)
		c += abs(f[i] - f[i + 1]);
	cout << c;
}
int main()
{
    ios_base::sync_with_stdio();
    cin >> n;
    for (long i = 1; i <= n; ++i)
	{
		cin >> x;
		f[x] = i;
	}
	Solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
struct Element
{ long x, p; };
long n; Element f[2*MAXN+5];
bool compare(Element a, Element b)
{ return (a.x < b.x); }
void Solve()
{
	long c = 0;
	for (long i = 1; i < n; ++i)
		c += abs(f[i].p - f[i + 1].p);
	cout << c;
}
int main()
{
    ios_base::sync_with_stdio();
    cin >> n;
    for (long i = 1; i <= n; ++i)
	{
		cin >> f[i].x;
		f[i].p = i;
	}
	sort(f + 1, f + n + 1, compare);
	Solve();
    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
struct so{
	long so;
	long chiso;
};
so *a;
bool sosanh(const so &x, const so &y){
	return (x.so > y.so);
}
int main(){
	long n;
	a = new so[n];
	long long dem=0;
	cin >> n;
	for(long i=0 ; i<n ; i++){
		cin >> a[i].so;
		a[i].chiso = i;
	}
	sort(a,a+n,sosanh);
	for(long i=0 ; i<n-1 ; i++){
		dem+=fabs(a[i].chiso - a[i+1].chiso);
	}
	cout << dem;

	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main(){
	long n,*a,*b;
	long long dem=0;
	cin >> n;
	a = new long[n];
	b = new long [n+1];
	for(long i=0 ; i<n ; i++){
		cin >> a[i];
		b[a[i]] = i+1;
	}
	for(long i=1 ; i<n ; i++){
		dem+=fabs(b[i]-b[i+1]);
	}
	cout << dem;

	return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
void sortt(int a[],int b[],int left, int right){
    int chot = a[(left+right)/2];
    int i=left,j=right;
    while(i<=j){
        while(a[i] < chot) i++;
        while(a[j] > chot) j--;
        if(i <= j){
            swap(a[i],a[j]);
            swap(b[i],b[j]);
            i++; j--;
        }
    }
    if(i<right) sortt(a,b,i,right);
    if(j>left) sortt(a,b,left,j);
}
int main(){
    int n,*a,*b,dem=0;
    cin >> n;
    a = new int[n];
    b = new int [n];
    for(int i=0 ; i<n ; i++){
        cin >> a[i];
        b[i] = i+1;
    }
    sortt(a,b,0,n-1);
    for(int i=n-1 ; i>0 ; i--){
        dem+=fabs(b[i]-b[i-1]);
    }
    cout << dem;

    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
void sortt(long a[],long b[],long left, long right){
    long chot = a[(left+right)/2];
    long i=left,j=right;
    while(i<=j){
        while(a[i] < chot) i++;
        while(a[j] > chot) j--;
        if(i <= j){
            swap(a[i],a[j]);
            swap(b[i],b[j]);
            i++; j--;
        }
    }
    if(i<right) sortt(a,b,i,right);
    if(j>left) sortt(a,b,left,j);
}
int main(){
    long n,*a,*b;
    long long dem=0;
    cin >> n;
    a = new long[n];
    b = new long [n];
    for(long i=0 ; i<n ; i++){
        cin >> a[i];
        b[i] = i+1;
    }
    sortt(a,b,0,n-1);
    for(long i=n-1 ; i>0 ; i--){
        dem+=fabs(b[i]-b[i-1]);
    }
    cout << dem;

    return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace::std;
int n,add,t,p,counter,next;
int TAB[200009];
int POZ[200009];

int main(){

cin>>n;

for(int i=0; i<n; i++){

    cin>>TAB[i];
    POZ[TAB[i]]=i;
    if(TAB[i]==1) p=i;
}

int sum=0;
for(int i=2; i<=n; i++){
int x= POZ[i]-POZ[i-1];
if(x<0) x=-x;
sum+=x;
p=i;
}
cout<<sum<<endl;

return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace::std;
int n,add,t,p,counter,next;
int TAB[200009];
int POZ[200009];

int main(){

cin>>n;

for(int i=0; i<n; i++){

    cin>>TAB[i];
    POZ[TAB[i]]=i;
    if(TAB[i]==1) p=i;
}

unsigned long long int sum=0;
for(int i=2; i<=n; i++){
int x= POZ[i]-POZ[i-1];
if(x<0) x=-x;
sum+=x;
p=i;
}
cout<<sum<<endl;

return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace::std;
int n,add,t,p,counter,next;
int TAB[200009];
int POZ[200009];

int main(){

cin>>n;

for(int i=0; i<n; i++){

    cin>>TAB[i];
    POZ[TAB[i]]=i;
    if(TAB[i]==1) p=i;
}

int sum=0;
for(int i=1; i<=n; i++){
int x= POZ[i]-POZ[p];
if(x<0) x=-x;
sum+=x;
p=i;
}
cout<<sum<<endl;

return 0;
}


#include <iostream>
#include <vector>
using namespace::std;
int n,add,p,counter,next;
int TAB[200009];
bool V[200009];
int main(){

cin>>n;
for(int i=0; i<n; i++){
    cin>>TAB[i];
}
counter=-1;
next=1;
while(next!=n+1){

    add=0;
    for(int i=p; i<n; i++){
        if(V[i]) continue;
        add++;
        if(TAB[i]==next){
            V[i]=true;
            p=i;
            next++;
            counter+=add;

            break;
        }

    }
    add=0;
    for(int i=p; i>=0; i--){
        if(V[i]) continue;
        add++;
        if(TAB[i]==next){
            V[i]=true;
            p=i;
            counter+=add;

            next++;
            break;
        }

    }
    add=0;
}
cout<<counter<<endl;

return 0;
}


#include <iostream>
#include <vector>
#include <math.h>
using namespace::std;
int n,add,t,p,counter,next;
int TAB[200009];
bool V[200009];

int znajdz_prawo(int p, int szukana){

for(int i=p; i<n; i++){
    if(TAB[i]==szukana) {
        return i;
    }
}
return -1;
}
int znajdz_lewo(int p, int szukana){
for(int i=p; i>=0; i--){
    if(TAB[i]==szukana) {
        return i;
    }
}
return -1;
}
int main(){

cin>>n;
for(int i=0; i<n; i++){
    cin>>TAB[i];
    if(TAB[i]==1) p=i;
}
counter=0;
next=1;
while(next!=n+1){
   t=0;
   t=znajdz_prawo(p, next);
    if(t==-1){
    t=znajdz_lewo(p,next);
    }
    int x=p-t;
   if(x<0) x=-x;
   p=t;
counter+=x;
next++;
}
cout<<counter<<endl;
return 0;
}


#include <iostream>
#include <vector>
using namespace::std;
int n,add,p,counter,next;
int TAB[100009];
bool V[100009];
int main(){

cin>>n;
for(int i=0; i<n; i++){
    cin>>TAB[i];
}
counter=-1;
next=1;
while(next!=n+1){

    add=0;
    for(int i=p; i<n; i++){
        if(V[i]) continue;
        add++;
        if(TAB[i]==next){
            V[i]=true;
            p=i;
            next++;
            counter+=add;

            break;
        }

    }
    add=0;
    for(int i=p; i>=0; i--){
        if(V[i]) continue;
        add++;
        if(TAB[i]==next){
            V[i]=true;
            p=i;
            counter+=add;

            next++;
            break;
        }

    }
    add=0;
}
cout<<counter<<endl;

return 0;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n,h;
    cin >>n;
    int a[n];
    for (int i=0;i<n;i++)
    {cin >>a[i];
    if (a[i]==1) h=i;}
    int g=0;
    for (int i=2;i<=n;i++)
    {
        for (int j=0;j<n;j++)
        {

if (a[j]==i){
        g+=std::abs(j-h);h=j;
    }
        }
    }
    cout <<g;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n,h,s=0;
    cin >>n;
    int a[n+1];
    a[0]=0;
for (int i=1;i<=n;i++) {
cin >>h;
a[h]=i;
}
for (int i=1;i<n;i++)
{
 s+=abs(a[i]-a[i-1]);
}
cout <<s;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n;
    cin >>n;
    int a[n];
    for (int i=0;i<n;i++)
    cin >>a[i];
    int g=0,h=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<n;j++)
        {

        if (a[j]==i && i==1) {h=j;g+=std::abs(j-h);}
    else if (a[j]==i)
        g+=std::abs(j-h);h=j;
    }
        }

    cout <<g;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n,h,s=0;
    cin >>n;
    int a[n];
for (int i=0;i<n;i++) {
cin >>h;
a[i]=h;
}
for (int i=1;i<n;i++)
{
 s+=abs(a[i]-a[i-1]);
}
cout <<s;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n,h,s=0;
    cin >>n;
    int a[n+1];

for (int i=1;i<=n;i++) {
cin >>h;
a[h]=i;
}
for (int i=2;i<=n;i++)
{
 s+=abs(a[i]-a[i-1]);
}
cout <<s;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n,h;
    cin >>n;
    int a[n];
    for (int i=0;i<n;i++)
    {cin >>a[i];
    if (a[i]==1) h=i;}
    int g=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<n;j++)
        {

if (a[j]==i){
        g+=std::abs(j-h);h=j;
    }
        }
    }
    cout <<g;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n,h,s=0;
    cin >>n;
    int a[n];

for (int i=1;i<=n;i++) {
cin >>h;
a[h]=i;
}
for (int i=2;i<=n;i++)
{
 s+=abs(a[i]-a[i-1]);
}
cout <<s;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    int n;
    cin >>n;
    int a[n];
    for (int i=0;i<n;i++)
    cin >>a[i];
    int g=0,h;
    for (int i=0;i<n;i++)
    if (a[i]==1) {h=i;break;}
    for (int i=1;i<=n;i++)
    {
        for (int j=0;j<n;j++)
        if (a[j]==i) {g+=std::abs(j-h);h=j;}

    }
    cout <<g;
}


#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main ()
{
    long long n,h,s=0;
    cin >>n;
    long long a[n+1];

for (int i=1;i<=n;i++) {
cin >>h;
a[h]=i;
}
for (int i=2;i<=n;i++)
{
 s+=abs(a[i]-a[i-1]);
}
cout <<s;
}


#include<iostream>
#include<math.h>
using namespace std;
int main(){
int y=0,i,s,n,a[200001];
cin>>n;
for (i=1;i<=n;i++)
{
cin>>s;
a[s]=i;
}
for (i=1;i<n;i++)y+=(a[i]-a[i+1])*((a[i]-a[i+1]>0)?1:-1);
cout<<y;

	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main(){
int y=0,i,s,n;
int a[200010];
cin>>n;
for (i=1;i<=n;i++)
{
cin>>s;
a[s]=i;
}
for (i=1;i<n;i++)y+=(a[i]-a[i+1])*((a[i]-a[i+1]>0)?1:-1);
cout<<y;

	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main(){
long long y=0,i,s,n;
long long a[200010];
cin>>n;
for (i=1;i<=n;i++)
{
cin>>s;
a[s]=i;
}
for (i=1;i<n;i++)y+=(a[i]-a[i+1])*((a[i]-a[i+1]>0)?1:-1);
cout<<y;

	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main(){
int y=0,i,s,n,a[200001];
cin>>n;
for (i=1;i<=n;i++)
{
cin>>s;
a[s]=i;
}
for (i=1;i<n;i++)y+=abs(a[i]-a[i+1]);
cout<<y;

	return 0;
}


#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;

int gcd(int a,int b){
	if (a==b || a==0) return b;
	if (a>b) return gcd(a%b,b); return gcd(b % a, a);
}
float dist(int x1,int y1,int x2,int y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int bins(int l, int r )
{
	cout<<l<<" "<<r<<endl;
	char a=getch();
	if((int) a-'0'==0) return (l+r)/2;
	if((int) a-'0'>1) return bins(l,(l+r)/2); else return bins((l+r)/2,r);
}
int binpow(int a, int n){
	if(n == 0) return 1;
	if (n % 2 == 1) return binpow(a,n-1)*a;
	return binpow(a,n/2)*binpow(a,n/2);
}
int main(){
int y=0,i,s,n,a[200001];
cin>>n;
for (i=1;i<=n;i++)
{
cin>>s;
a[s]=i;
}
for (i=1;i<n;i++)
y+=abs(a[i]-a[i+1]);
cout<<y;

	return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long n,s;
pair < long , long > a[200200];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(a,a+n);
    for(int i=1;i<n;i++){
        s+=abs(a[i].second-a[i-1].second);
    }
    cout<<s;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
long long n,s;
pair < long , long > a[200200];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(a+1,a+n+1);
    for(int i=2;i<=n;i++){
        s += abs(a[i].second-a[i-1].second);
    }
    cout<<s;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
long n,s;
pair < long , long > a[200200];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(a,a+n);
    for(int i=1;i<n;i++){
        s+=abs(a[i].second-a[i-1].second);
    }
    cout<<s;
}


#include<iostream>
#include<cstring>
using namespace std;
long n,a[200200],s;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s+=a[i]-1;
    }
    cout<<s;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long n,s;
pair < long , long > a[200200];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a,a+n);
    for(int i=1;i<n;i++){
        s+=abs(a[i].second-a[i-1].second);
    }
    cout<<s;
}


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
long n,s;
pair < long , long > a[200200];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(a+1,a+n+1);
    for(int i=2;i<=n;i++){
        s += abs(a[i].second-a[i-1].second);
    }
    cout<<s;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=222222;
typedef long long ll;
struct node
{
    int x,id;
    bool operator<(const node&p)const
    {
        return x<p.x;
    }
}A[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%I64d",&A[i].x);
            A[i].id=i;
        }
        sort(A+1,A+n+1);
        ll total=0;
        for(int i=2;i<=n;i++)
        {
             total+=abs(A[i].id-A[i-1].id);
        }
        printf("%I64d\n",total);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=222222;
typedef long long ll;
ll A[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%I64d",&A[i]);
        ll total=0;
        for(int i=2;i<=n;i++)
        {
             total+=abs(A[A[i]]-A[A[i-1]]);
             printf("%I64d\n",total);
        }

        printf("%I64d\n",total);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=222222;
typedef long long ll;
ll A[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%I64d",&A[i]);
        ll total=0;
        for(int i=2;i<=n;i++)
        {
             total+=abs(A[A[i]]-A[A[i-1]]);
        }

        printf("%I64d\n",total);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=222222;
typedef long long ll;
int A[maxn];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&A[i]);
        ll total=0;
        for(int i=2;i<=n;i++)
        {
             total+=abs(A[A[i]]-A[A[i-1]]);
        }

        printf("%I64d\n",total);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
typedef struct s
{
	int n;
	int number;
}shu;
int main(void)
{
	shu a[200010];
	shu temp;
	int sum=0;
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++)
	  {
	  	  scanf("%d",&a[i].n);
	  	a[i].number=i;

	  }
	  int j;
	for(i=1;i<n;i++)
	  for(j=i+1;j<=n;j++)
	  {
	  	  if(a[i].n>a[j].n)
	  	    {
	  	    	  temp=a[j];
	  	    	  a[j]=a[i];
	  	    	  a[i]=temp;
				}
	  }
	for(i=1;i<n;i++)
	{
		  sum+=fabs(a[i+1].number-a[i].number);
	}
	printf("%d",sum);
	return 0;
}


#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[400000];

int main()
{
    int n;
    long long sum = 0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        a[x]=i;
    }

    for(int i=1;i<n;i++)
        sum+=abs(a[i+1]-a[i]);
    cout<<sum<<endl;
    return 0;
}


#include<stdio.h>
#include<math.h>
int main(void)
{
    int a[201000];
	 int b[201000];
	 int i;
	 int n;
	 scanf("%d",&n);
	 for(i=1;i<=n;i++)
	  {
	  		    scanf("%d",&a[i]);
	  		    b[a[i]]=i;
		  }
		  int sum=0;
	  for(i=1;i<n;i++)
	    {
	    	  sum+=fabs(b[i+1]-b[i]);

		 }
	    printf("%d",sum);
	    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    long a[n+1],b[n+1];
    for(long i = 1 ; i <=n ; i ++)
    {
        cin>>a[i];
        b[a[i]]=i;
    }

    long res = 0;
    for(long i = 1 ; i <=n-1 ; i ++)
    {
         res += abs(b[i+1] - b[i]);
    }

    cout<<res;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    long a[n+1],b[n+1];
    for(long i = 1 ; i <=n ; i ++)
    {
        cin>>a[i];
        b[i]=i;
    }
    for(long i = 1 ; i <= n-1 ; i ++)
        for(long j = i +1 ; j  <= n ; j ++)
        {
            if(a[i] > a[j])
            {
                swap(a[i],a[j]);
                swap(b[i],b[j]);

            }
        }
    long res = 0;
    for(long i = 1 ; i <=n-1 ; i ++)
    {
        res+=max(b[i+1]-b[i] , 0-b[i+1]+b[i] );
    }
//  for(long i = 1 ; i <=n-1 ; i ++)
//  cout<<a[i]<<endl;
    cout<<res;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n+1],b[n+1];
    for(int i = 1 ; i <=n ; i ++)
    {
        cin>>a[i];
        b[i]=i;
    }
    for(int i = 1 ; i <= n-1 ; i ++)
        for(int j = i +1 ; j  <= n ; j ++)
        {
            if(a[i] > a[j])
            {
                swap(a[i],a[j]);
                swap(b[i],b[j]);

            }
        }
    long res = 0;
    for(int i = 1 ; i <=n-1 ; i ++)
    {
        res+=max(b[i+1]-b[i] , 0-b[i+1]+b[i] );
    }
//  for(int i = 1 ; i <=n-1 ; i ++)
//  cout<<a[i]<<endl;
    cout<<res;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    long long a[n+1],b[n+1];
    for(long long i = 1 ; i <=n ; i ++)
    {
        cin>>a[i];
        b[a[i]]=i;
    }

    long long res = 0;
    for(long long i = 1 ; i <=n-1 ; i ++)
    {
         res += abs(b[i+1] - b[i]);
    }

    cout<<res;

    return 0;
}


#include<concurrent_priority_queue.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<math.h>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<iomanip>
#define P_Q priority_queue
#define V vector
#define L list
#define S stack
#define Q queue;
#define D deque
#define St set
#define M map
#define fr(i, n) for(int i = 0; i < n ; i++)
#define rep(i, n) for(int i = 1; i <= n; i++)
#define lp(i, strat, end) for(int i = start; i <= end; i++)
#define ef else if
#define el else
#define w while
#define sr(x) sqrt(x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define itr iterator
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    int def, count = 0, n, x, arr[200000];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        arr[x - 1] = i + 1;
    }
    for (int i = 1; i < n; i++)
    {
        def = abs(arr[i] - arr[i - 1]);
        count += def;
    }
    cout << count << endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<math.h>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<iomanip>
#define P_Q priority_queue
#define V vector
#define L list
#define S stack
#define Q queue;
#define D deque
#define St set
#define M map
#define fr(i, n) for(int i = 0; i < n ; i++)
#define rep(i, n) for(int i = 1; i <= n; i++)
#define lp(i, strat, end) for(int i = start; i <= end; i++)
#define ef else if
#define el else
#define w while
#define sr(x) sqrt(x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define itr iterator
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    int arr[200000], x, n;
    long long dif, count = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        arr[x - 1] = i + 1;
    }
    for (int i = 1; i < n; i++)
    {
        dif = abs(arr[i] - arr[i - 1]);
        count += dif;
    }
    cout << count << endl;
    return 0;
}


#include<concurrent_priority_queue.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<math.h>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<iomanip>
#define P_Q priority_queue
#define V vector
#define L list
#define S stack
#define Q queue;
#define D deque
#define St set
#define M map
#define fr(i, n) for(int i = 0; i < n ; i++)
#define rep(i, n) for(int i = 1; i <= n; i++)
#define lp(i, strat, end) for(int i = start; i <= end; i++)
#define ef else if
#define el else
#define w while
#define sr(x) sqrt(x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define itr iterator
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    int dif, count = 0, n, x, arr[200000];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        arr[x - 1] = i + 1;
    }
    for (int i = 1; i < n; i++)
    {
        dif = abs(arr[i] - arr[i - 1]);
        count += dif;
    }
    cout << count << endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<math.h>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<iomanip>
#define P_Q priority_queue
#define V vector
#define L list
#define S stack
#define Q queue;
#define D deque
#define St set
#define M map
#define fr(i, n) for(int i = 0; i < n ; i++)
#define rep(i, n) for(int i = 1; i <= n; i++)
#define lp(i, strat, end) for(int i = start; i <= end; i++)
#define ef else if
#define el else
#define w while
#define sr(x) sqrt(x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define itr iterator
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
int main()
{
    int dif, count = 0, n, x, arr[200000];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        arr[x - 1] = i + 1;
    }
    for (int i = 1; i < n; i++)
    {
        dif = abs(arr[i] - arr[i - 1]);
        count += dif;
    }
    cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n,a,b[200001],i,j,c=1;
    long long s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        b[a]=i;
    }
    i=b[1];
    while(c<n)
    {
        j=b[c+1];
        s+=abs(j-i);
        i=j;
        c++;
    }
    printf("%lld\n",s);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, x, c, i;long long sum = 0;
    map<int, int> m;
    map<int, int>::iterator it, it2;
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &x);
        m[x] = i + 1;
    }
    it = it2 = m.begin();
    it2++;
    for (; it2 != m.end(); ++it, ++it2)
    {
        c = abs(it2->second - it->second);
        sum += c;
    }
    printf("%lld", sum);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, x, c, sum = 0, i;
    map<int, int> m;
    map<int, int>::iterator it, it2;
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
    {
        scanf("%d", &x);
        m[x] = i + 1;
    }
    it = it2 = m.begin();
    it2++;
    for (; it2 != m.end(); ++it, ++it2)
    {
        c = abs(it2->second - it->second);
        sum += c;
    }
    printf("%lld", sum);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n,a,b[200001],i,j,c=1,m;
    long long s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        b[a]=i;
    }
    i=b[1];
    while(c<n)
    {
        j=b[c+1];
        m=abs(j-i)<=(n-j+i)?abs(j-i):(n-j+i);
        s+=abs(j-i);
        i=j;
        c++;
    }
    printf("%lld\n",s);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f(a,b,c) for(int a = b; a < c; a++)
#define order(a, n) sort(a, a+n)
#define s(a) scanf("%d", &a)

int pos[200001];

int main(){

	int t;
	s(t);

	int aux;
	f(i,1,t+1){
		s(aux);
		pos[aux] = i;
	}

	long long int tempo = 0;
	int p = pos[1];
	f(i,1,t+1){
		tempo += abs(p - pos[i]);
		p = pos[i];
	}

	printf("%lld\n", tempo);

	return 0;
}
// 1453786188880


#include <stdio.h>
#include <math.h>

using namespace std;
typedef struct i {
	int val;
	int sec;
}data;

int partition( data a[], int l, int r) {
   data pivot, t;
   int i, j;
   pivot = a[l];
   i = l; j = r+1;

   while( 1)
   {
   	do ++i; while( a[i].val <= pivot.val && i <= r );
   	do --j; while( a[j].val > pivot.val );
   	if( i >= j ) break;
   	t = a[i]; a[i] = a[j]; a[j] = t;
   }
   t = a[l]; a[l] = a[j]; a[j] = t;
   return j;
}

void quickSort( data a[], int l, int r)
{
   int j;

   if( l < r )
   {
   	// divide and conquer
        j = partition( a, l, r);
       quickSort( a, l, j-1);
       quickSort( a, j+1, r);
   }

}

int n;
long long t;
data hdd[2000000];
int main() {
	scanf("%d", &n);
	t = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &hdd[i].val);
		hdd[i].sec = i;
	}
	quickSort(hdd, 0, n-1);
	for (int i = 1; i < n; i++) {
		t+= fabs(hdd[i].sec - hdd[i-1].sec);
	}
	printf("%lld", t);
	return 0;
}
// 1453604126532


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define fri(a, b, c) for(a = b; a < c; a++)
#define fpr(a) freopen (a, "r", stdin)
#define sci1(a) scanf("%d", &a)

int main() {
	int n;
	unsigned long long sum = 0;
	sci1(n);
	int a[n+1], i, k;
	a[0] = 0;
	fri(i, 1, n+1) {
		sci1(k);
		a[k] = i;
	}

	fri(k, 1, n) {
		sum += abs(a[k] - a[k+1]);
	}

	printf("%d", sum);
	return 0;
}
// 1453774209168


#include <bits/stdc++.h>
#define f(i,a,b) for (int i=a;i<b;i++)
//#define MAX 1000000000

using namespace std;

int main(){

    //freopen("t.in","r",stdin);
    //freopen("t.out","w",stdout);

    int n, total=0;

    scanf("%d",&n);

    int aux[n];
    int d[n];

    f(i,0,n) {
        scanf("%d",&aux[i]);
        d[aux[i]-1] = i;
    }

    //f(i,0,n) printf("%d ",d[i]);

    f(i,0,n-1){
        total += abs(d[i+1]-d[i]);
    }

    printf("%d\n",total);

    return 0;
}
// 1453741406821


#include <stdio.h>
#include <math.h>

using namespace std;
typedef struct i {
	int val;
	int sec;
}data;

int partition( data a[], int l, int r) {
   data pivot, t;
   int i, j;
   pivot = a[l];
   i = l; j = r+1;

   while( 1)
   {
   	do ++i; while( a[i].val <= pivot.val && i <= r );
   	do --j; while( a[j].val > pivot.val );
   	if( i >= j ) break;
   	t = a[i]; a[i] = a[j]; a[j] = t;
   }
   t = a[l]; a[l] = a[j]; a[j] = t;
   return j;
}

void quickSort( data a[], int l, int r)
{
   int j;

   if( l < r )
   {
   	// divide and conquer
        j = partition( a, l, r);
       quickSort( a, l, j-1);
       quickSort( a, j+1, r);
   }

}

int n, t;
data hdd[200000];
int main() {
	scanf("%d", &n);
	t = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &hdd[i].val);
		hdd[i].sec = i;
	}
	quickSort(hdd, 0, n-1);
	for (int i = 1; i < n; i++) {
		t+= fabs(hdd[i].sec - hdd[i-1].sec);
	}
	printf("%d", t);
	return 0;
}
// 1453603646741


#include <stdio.h>
#include <math.h>

using namespace std;

int n;
long long t;
int hdd[2000000];
int val;
int main() {
	scanf("%d", &n);
	t = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &val);
		hdd[val] = i;
	}
	for (int i = 2; i <= n; i++) {
		t+= fabs(hdd[i]-hdd[i-1]);
	}
	printf("%lld", t);
	return 0;
}
// 1453607482132


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int arr[2*100001]={0},pos[2*100001]={-100};

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        pos[arr[i]-1]=i;
    }

    long long int sum=0;
    for(int i=1;i<n;i++)
    {
        sum=sum+abs(pos[i]-pos[i-1]);

    }

    cout<<sum;

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int arr[2*100001]={0};

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int pos,tpos;
    for(int i=0;i<n;i++)
    {
        if(arr[i]==1)
        {
            pos=i;
            break;
        }
    }
    int num=2;
    long long int sum=0;
    for(int i=0;i<n;)
    {   //cout<<num<<"-"<<i<<"^^";
        if(num==arr[i])
        {//cout<<"*";
            tpos=i;
            sum=sum+abs(tpos-pos);
            pos=tpos;
            num++;
            i=0;
        }
        else
            i++;
        if(num>n)
        {/*cout<<"+";   */ break; }
    }
    cout<<sum;

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;

int arr[2*100001]={0};
int find(int num,int n)
{
    for(int i=0;i<n;i++)
    {
        if(num==arr[i])
        {/*cout<<i<<"+";*/    return i;}
    }
    return 0;
}

int main() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int pos;
    pos=find(1,n);
    int num=2;
    long long int sum=0;
    for(int i=0;i<n-1;i++)
    {    //cout<<pos<<"*";
        sum=sum+abs(pos-find(num,n));
        pos=find(num,n);
        num++;
    }
    cout<<sum;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[200001]={0};
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int pos=0,num=1,ans=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i]==num)
            pos=i;
    }//cout<<pos<<"*";
    while(num<=n)
    {
        for(int i=0;i<n;i++)
        {
            if(arr[i]==num)
            {   // cout<<i<<"**";
                ans=ans+abs(i-pos);
                pos=i;
                num++;
            }
        }
    }
    cout<<ans;

    return 0;

}


#include <stdio.h>
#include <math.h>

using namespace std;
typedef struct i {
	int val;
	int sec;
}data;

int partition( data a[], int l, int r) {
   data pivot, t;
   int i, j;
   pivot = a[l];
   i = l; j = r+1;

   while( 1)
   {
   	do ++i; while( a[i].val <= pivot.val && i <= r );
   	do --j; while( a[j].val > pivot.val );
   	if( i >= j ) break;
   	t = a[i]; a[i] = a[j]; a[j] = t;
   }
   t = a[l]; a[l] = a[j]; a[j] = t;
   return j;
}

void quickSort( data a[], int l, int r)
{
   int j;

   if( l < r )
   {
   	// divide and conquer
        j = partition( a, l, r);
       quickSort( a, l, j-1);
       quickSort( a, j+1, r);
   }

}

int n;
long long t;
data hdd[200001];
int main() {
	scanf("%d", &n);
	t = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &hdd[i].val);
		hdd[i].sec = i;
	}
	quickSort(hdd, 0, n-1);
	for (int i = 1; i < n; i++) {
		t+= fabs(hdd[i].sec - hdd[i-1].sec);
	}
	printf("%lld", t);
	return 0;
}
// 1453604052363


#include <stdio.h>
#include <math.h>

using namespace std;

int search(int *vec, int target) {
	for (int i = 0; ; i++) {
		if (vec[i] == target)
			return i;
	}
}

int n;
long long t;
int hdd[2000000];
int main() {
	scanf("%d", &n);
	t = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &hdd[i]);
	}
	for (int i = 2; i <= n; i++) {
		t+= fabs(search(hdd,i)-search(hdd,i-1));
	}
	printf("%lld", t);
	return 0;
}
// 1453607193558


#include <stdio.h>
#include <stdlib.h>

int a[200010];

int main()
{
  int n, m, result = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
  {
    scanf("%d", &m);
    a[m - 1] = i;
  }
  for(int i = 1; i < n; i++)
    result += abs(a[i] - a[i - 1]);
  printf("%d\n", result);
}
// 1453658333083


#include <bits/stdc++.h>
#define f(i,a,b) for (int i=a;i<b;i++)
//#define MAX 1000000000

using namespace std;

int main(){

    //freopen("t.in","r",stdin);
    //freopen("t.out","w",stdout);

    int n, total=0;

    scanf("%d",&n);

    int aux[n];

    f(i,0,n) scanf("%d",&aux[i]);

    int a = 1, b = 2;
    int y, w;

    for (int i=0;i<(n-1);i++){
        for (int p=0;p<n;p++) if (aux[p] == a) y = p;
        for (int o=0;o<n;o++) if (aux[o] == b) w = o;
        total += abs(y-w);
        a++;
        b++;
    }

    printf("%d\n",total);

    return 0;
}
// 1453740513446


#include <bits/stdc++.h>
using namespace std;

#define f(a,b,c) for(int a = b; a < c; a++)
#define order(a, n) sort(a, a+n)
#define s(a) scanf("%d", &a)

int pos[200001];

int main(){

	int t;
	s(t);

	int aux;
	f(i,1,t+1){
		s(aux);
		pos[aux] = i;
	}

	int tempo = 0;
	int p = pos[1];
	f(i,1,t+1){
		tempo += abs(p - pos[i]);
		p = pos[i];
	}

	printf("%d\n", tempo);

	return 0;
}
// 1453786026629


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <iostream>
#include <set>
#include <cmath>
#include <cassert>
#include <ctime>
#include <string>

using namespace std;

#define db(x) cout << #x " == " << x << endl
#define _ << ", " <<
#define fr(a,b,c) for(int a = b; a < c; a++)
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = ant[b]; ~a; a = ant[a])
#define cl(a,b) memset(a,b,sizeof(a))

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define add_edge(a,b) to[z] = b; ant[z] = adj[a]; adj[a] = z; nei[a]++; z++
#define oo 0x3f3f3f3f3f3f3f3f

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

int N, val;
pii ar[200010];

bool comp(const pii &a, const pii &b){
	return a.first < b.first;
}

int main(){
	scanf("%d",&N);
	rp(n, N){
		scanf("%d",&val);
		ar[n] = pii(val, n);
	}
	sort(ar, ar+N, comp);
	ll counter = 0;
	rp(n, N-1){
		//printf("%d %d\n", ar[n].first, ar[n].second);
		counter += abs(ar[n].second-ar[n+1].second);
	}
	cout << counter << endl;
}
// 1453671181492


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long t;
  cin >> t;
  while (t > 0) {
    int n;
    cin >> n;
    vector<int> ar(n);
    vector<int> bol(10010, 0);
    vector<int> pb;
    for (int i = 0; i < n; ++i) {
      cin >> ar[i];
      bol[ar[i]]++;
      if (bol[ar[i]] == 2) {
        pb.push_back(ar[i]);
      }
    }

    if (n == 4) {
      if (pb.size() == 1) {
        cout << pb[0] << ' ' << pb[0] << ' ' << pb[0] << ' ' << pb[0] << endl;
      } else {
        cout << pb[0] << ' ' << pb[0] << ' ' << pb[1] << ' ' << pb[1] << endl;
      }
    } else {
      sort(pb.begin(), pb.end());

      int prev = -1;
      float min = INT_MAX*1.0;
      int x, y;
      for (int i = 0; i < pb.size(); ++i) {
        if (bol[pb[i]] == 2) {
          if (prev != -1) {
            float tec = (prev*1.0 / pb[i]*1.0);
            float quant = 8.0 + 4*(tec + (1/tec));
            if (quant < min) {
              min = quant;
              x = prev;
              y = pb[i];
            }
          }
          prev = pb[i];
        }
        if (bol[pb[i]] >= 4) {
          float quant = 16.0;
          if (quant < min) {
            min = quant;
            x = pb[i];
            y = pb[i];
          }
          if (prev == -1) {
            prev = pb[i];
          }
        }
      }
      cout << x << ' ' << x << ' ' << y << ' ' << y << endl;
    }

    t--;
  }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long t;
  cin >> t;
  while (t > 0) {
    int n;
    cin >> n;
    vector<int> bol(10050, 0);
    vector<int> pb;
    for (int i = 0; i < n; ++i) {
      int temp;
      cin >> temp;
      bol[temp]++;
      if (bol[temp] == 2) {
        pb.push_back(temp);
      }
    }

    sort(pb.begin(), pb.end());

    int prev = -1;
    float min = INT_MAX*1.0;
    int x, y;
    for (int i = 0; i < pb.size(); ++i) {
      if (bol[pb[i]] == 2) {
        if (prev != -1) {
          float tec = (prev*1.0 / pb[i]*1.0);
          float quant = 8.0 + 4*(tec + (1/tec));
          if (quant < min) {
            min = quant;
            x = prev;
            y = pb[i];
          }
        }
      }
      if (bol[pb[i]] >= 4) {
        float quant = 16.0;
        if (quant < min) {
          min = quant;
          x = pb[i];
          y = pb[i];
        }
      }
      prev = pb[i];
    }
    cout << x << ' ' << x << ' ' << y << ' ' << y << endl;
    t--;
  }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long t;
  cin >> t;
  while (t > 0) {
    int n;
    cin >> n;
    vector<int> ar(n);
    vector<int> bol(10050, 0);
    vector<int> pb;
    for (int i = 0; i < n; ++i) {
      cin >> ar[i];
      bol[ar[i]]++;
      if (bol[ar[i]] == 2) {
        pb.push_back(ar[i]);
      }
    }

    if (n == 4) {
      if (pb.size() == 1) {
        cout << pb[0] << ' ' << pb[0] << ' ' << pb[0] << ' ' << pb[0] << endl;
      } else {
        cout << pb[0] << ' ' << pb[0] << ' ' << pb[1] << ' ' << pb[1] << endl;
      }
    } else {
      sort(pb.begin(), pb.end());

      int prev = -1;
      float min = INT_MAX*1.0;
      int x, y;
      for (int i = 0; i < pb.size(); ++i) {
        if (bol[pb[i]] == 2) {
          if (prev != -1) {
            float tec = (prev*1.0 / pb[i]*1.0);
            float quant = 8.0 + 4*(tec + (1/tec));
            if (quant < min) {
              min = quant;
              x = prev;
              y = pb[i];
            }
          }
        }
        if (bol[pb[i]] >= 4) {
          float quant = 16.0;
          if (quant < min) {
            min = quant;
            x = pb[i];
            y = pb[i];
          }
        }
        prev = pb[i];
      }
      cout << x << ' ' << x << ' ' << y << ' ' << y << endl;
    }

    t--;
  }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long t;
  cin >> t;
  while (t > 0) {
    int n;
    cin >> n;
    vector<int> bol(10050, 0);
    vector<int> pb;
    float min = INT_MAX*1.0;
    int x, y;
    for (int i = 0; i < n; ++i) {
      int temp;
      cin >> temp;
      bol[temp]++;
      if (bol[temp] == 2) {
        pb.push_back(temp);
      }
      if (bol[temp] == 4) {
        if (16.0 < min) {
          min = 16.0;
          x = temp;
          y = temp;
        }
      }
    }

    sort(pb.begin(), pb.end());

    for (int i = 1; i < pb.size(); ++i) {
      float tec = (pb[i-1]*1.0 / pb[i]*1.0);
      float quant = 8.0 + 4*(tec + (1/tec));
      if (quant < min) {
        min = quant;
        x = pb[i-1];
        y = pb[i];
      }
    }
    cout << x << ' ' << x << ' ' << y << ' ' << y << endl;
    t--;
  }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long t;
  cin >> t;
  while (t > 0) {
    int n;
    cin >> n;
    vector<int> ar(n);
    vector<int> bol(10010, 0);
    vector<int> pb;
    for (int i = 0; i < n; ++i) {
      cin >> ar[i];
      bol[ar[i]]++;
      if (bol[ar[i]] == 2) {
        pb.push_back(ar[i]);
      }
    }

    sort(pb.begin(), pb.end());

    int prev = -1;
    float min = INT_MAX*1.0;
    int x, y;
    for (int i = 0; i < pb.size(); ++i) {
      if (bol[pb[i]] == 2) {
        if (prev != -1) {
          float tec = (prev*1.0 / pb[i]*1.0);
          float quant = 8.0 + 4*(tec + (1/tec));
          if (quant < min) {
            min = quant;
            x = prev;
            y = pb[i];
          }
        }
        prev = pb[i];
      }
      if (bol[pb[i]] >= 4) {
        float quant = 16.0;
        if (quant < min) {
          min = quant;
          x = pb[i];
          y = pb[i];
        }
        if (prev == -1) {
          prev = pb[i];
        }
      }
    }
    cout << x << ' ' << x << ' ' << y << ' ' << y << endl;
    t--;
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];
vector<int> nlist;

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
        ms(b);
    	nlist.clear();

    	for(int i=0; i<n; ++i) cin>>a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int ans = -1;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			nlist.push_back(i);
                if(b[i] >= 4){
                    ans = i;
                    break;
                }
    		}
    	}

    	if(ans != -1){
    		printf("%d %d %d %d\n", ans, ans, ans, ans);
    		continue;
    	}

        sort(nlist.begin(), nlist.end());

    	double check_num;
    	double min=inf;
    	int left, right;

        int beg = nlist[0];

    	for(int i=1; i<=nlist.size()-1; ++i) {
			check_num = 1.0 * (beg + nlist[i]) * (beg + nlist[i]) / (beg * nlist[i]);
			if(check_num < min) {
				left = beg;
				right = nlist[i];
				min = check_num;
			}
			beg = nlist[i];

    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
#define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) scanf("%d", &a[i]);
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	int check;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			beg = i;
                check = b[i];
    			break;
    		}
    	}

    	if(check >= 4){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
                break;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	int check;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			beg = i;
                check = b[i];
    			break;
    		}
    	}

    	if(check >= 4){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
                b[i] = 0;
                break;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
                b[i] = 0;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] == 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
const int inf = 0x3f3f3f3f;
//#define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin>>a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	int check;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			beg = i;
                check = b[i];
    			break;
    		}
    	}

    	if(check >= 4){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
                break;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] == 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	int check;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			beg = i;
                check = b[i];
    			break;
    		}
    	}

    	if(check >= 4){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
                b[i] = 0;
                break;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
                b[i] = 0;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	for(int i=0; i<=10000; ++i) b[i]=0;

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
const int inf = 0x3f3f3f3f;
#define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];
vector<int> nlist;

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
        ms(b);
    	nlist.clear();

    	for(int i=0; i<n; ++i) cin>>a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int ans = -1;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			nlist.push_back(i);
                if(b[i] >= 4){
                    ans = i;
                    break;
                }
    		}
    	}

    	if(ans != -1){
    		printf("%d %d %d %d\n", ans, ans, ans, ans);
    		continue;
    	}

        sort(nlist.begin(), nlist.end());

    	double check_num;
    	double min=inf;
    	int left, right;

        int beg = nlist[0];

    	for(int i=1; i<=nlist.size()-1; ++i) {
			check_num = 1.0 * (beg + nlist[i]) * (beg + nlist[i]) / (beg * nlist[i]);
			if(check_num < min) {
				left = beg;
				right = nlist[i];
				min = check_num;
			}
			beg = nlist[i];

    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	int check;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			beg = i;
                check = b[i];
    			break;
    		}
    	}

    	if(check >= 4){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
                break;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] == 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = 4.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
            if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] >= 4) {
    			left = i;
    			right = i;
                break;
    		}
    		if(b[i] >= 2) {
    			check_num = 1.0 * (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
const int inf = 0x3f3f3f3f;
//#define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];
vector<int> nlist;

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
        ms(b);
    	nlist.clear();

        int ans = -1;
    	for(int i=0; i<n; ++i) {
            cin>>a[i];
            b[a[i]]++;
            if(b[a[i]] == 2){
                nlist.push_back(a[i]);
            }
            if(b[a[i]] == 4){
                ans = a[i];
            }
        }

    	if(ans != -1){
    		printf("%d %d %d %d\n", ans, ans, ans, ans);
    		continue;
    	}

        sort(nlist.begin(), nlist.end());

    	double check_num;
    	double min=inf;
    	int left, right;

        int beg = nlist[0];

    	for(int i=1; i<=nlist.size()-1; ++i) {
			check_num = 1.0 * (beg + nlist[i]) * (beg + nlist[i]) / (beg * nlist[i]);
			if(check_num < min) {
				left = beg;
				right = nlist[i];
				min = check_num;
			}
			beg = nlist[i];

    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] == 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = (double)i/beg + beg/(double)i;
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
#define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] == 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = (beg + i) * (beg + i) / (beg * i);
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
const int inf = 0x3f3f3f3f;
// #define LOCAL

int k;
int n;
int a[1000000+10];
int b[10000+10];

int main() { _
    #ifdef LOCAL
    freopen("./input.txt", "r", stdin);
    #endif
    cin >> k;
    while(cin >> n) {
    	ms(b);

    	for(int i=0; i<n; ++i) cin >> a[i];
    	for(int i=0; i<n; ++i) b[a[i]]++;

    	int beg;
    	bool flag = false;
    	for(int i=1; i<=10000; ++i) {
    		if(b[i] >= 4){
    			flag = true;
    			beg = i;
    			break;
    		}else if(b[i] >= 2){
    			beg = i;
    			break;
    		}
    	}

    	if(flag){
    		printf("%d %d %d %d\n", beg, beg, beg, beg);
    		continue;
    	}

    	double check_num;
    	double min=inf;
    	int left, right;

    	for(int i=beg+1; i<=10000; ++i) {
    		if(b[i] == 4) {
    			left = i;
    			right = i;
    		}
    		if(b[i] >= 2) {
    			check_num = (double)i/(double)beg + (double)beg/(double)i;
    			if(check_num < min) {
    				left = beg;
    				right = i;
    				min = check_num;
    			}
    			beg = i;
    		}
    	}
    	printf("%d %d %d %d\n", left, left, right, right);

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

ld cmp(ll a, ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
	return x;
}

void solve(){
	int n;
	cin >> n;
	ll a[n];
	map <ll , int > mp;
	set <ll> s;
	for(int i =0;i<n;i++){
		cin >> a[i];
		mp[a[i]]++;
		s.insert(a[i]);
	}

	vector <ll> v;
	for(auto it = s.begin() ; it != s.end(); it++){
		if(mp[*it] >= 2){
		v.push_back(*it);
		}
	}
	int cap = v.size();

	ld _min = 99999999999999999.0;
	int l = 0;
	int x, y;
	while(l < cap){
		if(mp[v[l]] >= 4){
			x = y = l;
			break;
		}
		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
			_min = cmp(v[l], v[l+1]);
			x = l;
			y = l+1;
		}
		l++;
	}

	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

}

int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

ld cmp(ll a, ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
	return x;
}

void solve(){
	int n, temp;
	cin >> n;

	int freq[10001];
	memset(freq,0,sizeof(freq));
	for(int i =0;i<n;i++){
		cin >> temp;
		freq[temp]++;
	}

	vector <ll> v;
    for(int i=1; i<10001;i++){
    	if(freq[i] >= 2)v.push_back(i);
    }

	int cap = v.size();

	ld _min = 1e18;
	int l = 0;
	int x, y;
	while(l < cap){
		if(freq[v[l]] >= 4){
			x = y = l;
			break;
		}
		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
			_min = cmp(v[l], v[l+1]);
			x = l;
			y = l+1;
		}
		l++;
	}

	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


    #include <bits/stdc++.h>
    using namespace std;

    #define ll long long
    #define ld long double

    ld cmp(ll a, ll b){
    	ld x = 4*((ld)a/b + (ld)b/a) + 8;
    	return x;
    }

    void solve(){
    	int n;
    	cin >> n;
    	ll a[n];
    	int freq[10001];
    	memset(freq,0,sizeof(freq));
    	for(int i =0;i<n;i++){
    		cin >> a[i];
    		freq[a[i]]++;
    	}
    	sort(a, a+n);
    	vector <ll> v;
        v.push_back(a[0]);
        for(int i=1; i<n;i++){
        	if(a[i] != a[i-1] && freq[a[i]] >= 2)v.push_back(a[i]);
        }

    	int cap = v.size();

    	ld _min = 1e18;
    	int l = 0;
    	int x, y;
    	while(l < cap){
    		if(freq[v[l]] >= 4){
    			x = y = l;
    			break;
    		}
    		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
    			_min = cmp(v[l], v[l+1]);
    			x = l;
    			y = l+1;
    		}
    		l++;
    	}

    	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

    }

    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	cout.tie(NULL);
    	int t;
    	cin >> t;
    	while(t--){
    		solve();
    	}
    	return 0;
    }


#include <bits/stdc++.h>

using namespace std;

#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      	    cout<<"#x "<<x<<"\n";
#define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          	    cout<<"\n";

bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}

const long double PI = 3.1415926535;
const int         mod= 1e9+ 7;

ll n, q;

long double cmp(ll a ,ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
//	cout<<a<<" "<<b<<" "<<x<<"\n";
	return (ld)x;
}
void solve(){
     cin >> n;
     ll a[n];
     for(int i=0;i<n;i++)cin >> a[i];
     sort(a, a+ n);
     map <ll,int> m;
     for(int i= 0;i<n;i++){
	     m[a[i]]++;
     }
     set <ll> s;
     for(int i=0;i<n;i++)s.insert(a[i]);
     vector <ll> arr;
     for(auto it = s.begin(); it != s.end(); it++){
	    if(m[*it] >= 2)
	    arr.push_back(*it);
     }
     int sz =arr.size();
     int l = 0, r =sz-1;
     int v1, v2;
     ld k = LONG_MAX;
//     for(int i=0;i<sz;i++)cout<<arr[i]<<" ";
  //   cn;
     while(l < sz){

	       if(m[arr[l]] >= 4 && cmp(arr[l],arr[l]) < k){
		       k = min(k,cmp(arr[l], arr[l]));
		       v1 = l;
		       v2 = l;
	       }
	       if(l + 1 < sz && m[arr[l+1]]  >= 4 && cmp(arr[l+1],arr[l+1]) < k){
		       k = min(cmp(arr[l+1], arr[l+1]),k);
		       v1 = l+1;
		       v2 = l+1;
	       }
	       if(l+1 < sz && cmp(arr[l],arr[l+1]) < k){
		       k = cmp(arr[l+1], arr[l+1]);
		       v1 = l;
		       v2 = l+1;
	       }

               l++;
     }
     cout<<arr[v1]<<" "<<arr[v1]<<" "<<arr[v2]<<" "<<arr[v2]<<"\n";

}
int main(){
	int t;
        cin >> t;
	while(t--){
		solve();
	}
		return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      	    cout<<"#x "<<x<<"\n";
#define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          	    cout<<"\n";

bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}

const long double PI = 3.1415926535;
const int         mod= 1e9+ 7;

ll n, q;

long double cmp(ll a ,ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
//	cout<<a<<" "<<b<<" "<<x<<"\n";
	return (ld)x;
}
void solve(){
     cin >> n;
     ll a[n];
     for(int i=0;i<n;i++)cin >> a[i];
     sort(a, a+ n);
     map <ll,int> m;
     for(int i= 0;i<n;i++){
	     m[a[i]]++;
     }
     set <ll> s;
     for(int i=0;i<n;i++)s.insert(a[i]);
     vector <ll> arr;
     for(auto it = s.begin(); it != s.end(); it++){
	    if(m[*it] >= 2)
	    arr.push_back(*it);
     }
     int sz =arr.size();
     int l = 0, r =sz-1;
     int v1, v2;
     ld k = LONG_MAX;
//     for(int i=0;i<sz;i++)cout<<arr[i]<<" ";
  //   cn;
     while(l < sz){

	       if(m[arr[l]] >= 4 && cmp(arr[l],arr[l]) < k){
		       k = min(k,cmp(arr[l], arr[l]));
		       v1 = l;
		       v2 = l;
	       }
	       if(l + 1 < sz && m[arr[l+1]]  >= 4 && cmp(arr[l+1],arr[l+1]) < k){
		       k = min(cmp(arr[l+1], arr[l+1]),k);
		       v1 = l+1;
		       v2 = l+1;
	       }
	       if(l+1 < sz && cmp(arr[l],arr[l+1]) < k){
		       k = cmp(arr[l], arr[l+1]);
		       v1 = l;
		       v2 = l+1;
	       }

               l++;
     }
     cout<<arr[v1]<<" "<<arr[v1]<<" "<<arr[v2]<<" "<<arr[v2]<<"\n";

}
int main(){
	int t;
        cin >> t;
	while(t--){
		solve();
	}
		return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

ld cmp(ll a, ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
	return x;
}

void solve(){
	int n;
	cin >> n;
	ll a[n];
	map <ll , int > mp;
	set <ll> s;
	for(int i =0;i<n;i++){
		cin >> a[i];
		mp[a[i]]++;
		s.insert(a[i]);
	}

	vector <ll> v;
	for(auto it = s.begin() ; it != s.end(); it++){
		if(mp[*it] >= 2){
		v.push_back(*it);
		}
	}
	int cap = v.size();

	ld _min = 99999999999999999.0;
	int l = 0;
	int x, y;
	while(l < cap){
		if(mp[a[l]] >= 4){
			x = y = l;
			break;
		}
		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
			_min = cmp(v[l], v[l+1]);
			x = l;
			y = l+1;
		}
		l++;
	}

	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

}

int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


    #include <bits/stdc++.h>

    using namespace std;

    #define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define ld 		    long double
    #define ll 		    long long int
    #define ull 	   	    unsigned long long int
    #define pb		    push_back
    #define mp		    make_pair
    #define F		    first
    #define S		    second
    #define lb		    lower_bound
    #define ub		    upper_bound
    #define deb(x)      	    cout<<"#x "<<x<<"\n";
    #define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
    #define cn          	    cout<<"\n";

    bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
    bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}

    const long double PI = 3.1415926535;
    const int         mod= 1e9+ 7;

    ll n, q;

    long double cmp(ll a ,ll b){
    	ld x = 4*((ld)a/b + (ld)b/a) + 8;
    //	cout<<a<<" "<<b<<" "<<x<<"\n";
    	return (ld)x;
    }
    void solve(){
         cin >> n;
         ll a[n];
         for(int i=0;i<n;i++)cin >> a[i];
         sort(a, a+ n);
         map <ll,int> m;
         for(int i= 0;i<n;i++){
    	     m[a[i]]++;
         }
         set <ll> s;
         for(int i=0;i<n;i++)s.insert(a[i]);
         vector <ll> arr;
         for(auto it = s.begin(); it != s.end(); it++){
    	    if(m[*it] >= 2)
    	    arr.push_back(*it);
         }
         int sz =arr.size();
         int l = 0, r =sz-1;
         int v1, v2;
         ld k = LONG_MAX;
    //     for(int i=0;i<sz;i++)cout<<arr[i]<<" ";
      //   cn;
         while(l < sz){

    	       if(m[arr[l]] >= 4 && cmp(arr[l],arr[l]) < k){
    		       k = min(k,cmp(arr[l], arr[l]));
    		       v1 = l;
    		       v2 = l;
    	       }
    	       if(l + 1 < sz && m[arr[l+1]]  >= 4 && cmp(arr[l+1],arr[l+1]) < k){
    		       k = min(cmp(arr[l+1], arr[l+1]),k);
    		       v1 = l+1;
    		       v2 = l+1;
    	       }
    	       if(l+1 < sz && cmp(arr[l],arr[l+1]) < k){
    		       k = cmp(arr[l+1], arr[l+1]);
    		       v1 = l;
    		       v2 = l+1;
    	       }

                   l++;
         }
         cout<<arr[v1]<<" "<<arr[v1]<<" "<<arr[v2]<<" "<<arr[v2]<<"\n";

    }
    int main(){
    	int t;
            cin >> t;
    	while(t--){
    		solve();
    	}
    		return 0;
    }


    #include <bits/stdc++.h>

    using namespace std;

    #define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define ld 		    long double
    #define ll 		    long long int
    #define ull 	   	    unsigned long long int
    #define pb		    push_back
    #define mp		    make_pair
    #define F		    first
    #define S		    second
    #define lb		    lower_bound
    #define ub		    upper_bound
    #define deb(x)      	    cout<<"#x "<<x<<"\n";
    #define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
    #define cn          	    cout<<"\n";

    bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
    bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}

    const long double PI = 3.1415926535;
    const int         mod= 1e9+ 7;

    ll n, q;

    long double cmp(ll a ,ll b){
    	ld x = 4*((ld)a/b + (ld)b/a) + 8;
    //	cout<<a<<" "<<b<<" "<<x<<"\n";
    	return (ld)x;
    }
    void solve(){
         cin >> n;
         ll a[n];
         for(int i=0;i<n;i++)cin >> a[i];
         sort(a, a+ n);
         map <ll,int> m;
         for(int i= 0;i<n;i++){
    	     m[a[i]]++;
         }
         set <ll> s;
         for(int i=0;i<n;i++)s.insert(a[i]);
         vector <ll> arr;
         for(auto it = s.begin(); it != s.end(); it++){
    	    if(m[*it] >= 2)
    	    arr.push_back(*it);
         }
         int sz =arr.size();
         int l = 0, r =sz-1;
         int v1, v2;
         ld k = LONG_MAX;
    //     for(int i=0;i<sz;i++)cout<<arr[i]<<" ";
      //   cn;
         while(l < sz){

    	       if(m[arr[l]] >= 4 && cmp(arr[l],arr[l]) < k){
    		       k = min(k,cmp(arr[l], arr[l]));
    		       v1 = l;
    		       v2 = l;
    	       }
    	       if(l + 1 < sz && m[arr[l+1]]  >= 4 && cmp(arr[l+1],arr[l+1]) < k){
    		       k = min(cmp(arr[l+1], arr[l+1]),k);
    		       v1 = l+1;
    		       v2 = l+1;
    	       }
    	       if(l+1 < sz && cmp(arr[l],arr[l+1]) < k){
    		       k = cmp(arr[l+1], arr[l+1]);
    		       v1 = l;
    		       v2 = l+1;
    	       }

                   l++;
         }
         cout<<arr[v1]<<" "<<arr[v1]<<" "<<arr[v2]<<" "<<arr[v2]<<"\n";

    }
    int main(){
        IOS;
    	int t;
            cin >> t;
    	while(t--){
    		solve();
    	}
    		return 0;
    }


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

ld cmp(ll a, ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
	return x;
}

void solve(){
	int n;
	cin >> n;
	ll a[n];
	int freq[10001];
	memset(freq,0,sizeof(freq));
	for(int i =0;i<n;i++){
		cin >> a[i];
		freq[a[i]]++;
	}
	sort(a, a+n);
	vector <ll> v;
    v.push_back(a[0]);
    for(int i=1; i<n;i++){
    	if(a[i] != a[i-1] && freq[a[i]] >= 2)v.push_back(a[i]);
    }

	int cap = v.size();

	ld _min = 99999999999999999.0;
	int l = 0;
	int x, y;
	while(l < cap){
		if(freq[v[l]] >= 4){
			x = y = l;
			break;
		}
		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
			_min = cmp(v[l], v[l+1]);
			x = l;
			y = l+1;
		}
		l++;
	}

	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      	    cout<<"#x "<<x<<"\n";
#define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          	    cout<<"\n";

bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}

const long double PI = 3.1415926535;
const int         mod= 1e9+ 7;

ll n, q;

long double cmp(ll a ,ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
//	cout<<a<<" "<<b<<" "<<x<<"\n";
	return (ld)x;
}
void solve(){
	IOS;
     cin >> n;
     ll a[n];
     for(int i=0;i<n;i++)cin >> a[i];
     sort(a, a+ n);
     map <ll,int> m;
     for(int i= 0;i<n;i++){
	     m[a[i]]++;
     }
     set <ll> s;
     for(int i=0;i<n;i++)s.insert(a[i]);
     vector <ll> arr;
     for(auto it = s.begin(); it != s.end(); it++){
	    if(m[*it] >= 2)
	    arr.push_back(*it);
     }
     int sz =arr.size();
     int l = 0, r =sz-1;
     int v1=0, v2=0;
     ld k = LONG_MAX;
//     for(int i=0;i<sz;i++)cout<<arr[i]<<" ";
  //   cn;
     while(l < sz){

	       if(m[arr[l]] >= 4 && cmp(arr[l],arr[l]) < k){
		       k = min(k,cmp(arr[l], arr[l]));
		       v1 = l;
		       v2 = l;
	       }
	       if(l + 1 < sz && m[arr[l+1]]  >= 4 && cmp(arr[l+1],arr[l+1]) < k){
		       k = min(cmp(arr[l+1], arr[l+1]),k);
		       v1 = l+1;
		       v2 = l+1;
	       }
	       if(l+1 < sz && cmp(arr[l],arr[l+1]) < k){
		       k = cmp(arr[l], arr[l+1]);
		       v1 = l;
		       v2 = l+1;
	       }

               l++;
     }
     cout<<arr[v1]<<" "<<arr[v1]<<" "<<arr[v2]<<" "<<arr[v2]<<"\n";

}
int main(){
	int t;
        cin >> t;
	while(t--){
		solve();
	}
		return 0;
}


    #include <bits/stdc++.h>
    using namespace std;

    #define ll long long
    #define ld long double
     int freq[10001];
     ll a[1000001];
    ld cmp(ll a, ll b){
    	ld x = 4*((ld)a/b + (ld)b/a) + 8;
    	return x;
    }

    void solve(){
    	int n;
    	cin >> n;

    	memset(freq,0,sizeof(freq));
    	for(int i =0;i<n;i++){
    		cin >> a[i];
    		freq[a[i]]++;
    	}
    	sort(a, a+n);
    	vector <ll> v;
        v.push_back(a[0]);
        for(int i=1; i<n;i++){
        	if(a[i] != a[i-1] && freq[a[i]] >= 2)v.push_back(a[i]);
        }

    	int cap = v.size();

    	ld _min = 1e18;
    	int l = 0;
    	int x, y;
    	while(l < cap){
    		if(freq[v[l]] >= 4){
    			x = y = l;
    			break;
    		}
    		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
    			_min = cmp(v[l], v[l+1]);
    			x = l;
    			y = l+1;
    		}
    		l++;
    	}

    	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

    }

    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	cout.tie(NULL);
    	int t;
    	cin >> t;
    	while(t--){
    		solve();
    	}
    	return 0;
    }


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double

ld cmp(ll a, ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
	return x;
}

void solve(){
	int n;
	cin >> n;
	ll a[n];
	map <ll , int > mp;
	for(int i =0;i<n;i++){
		cin >> a[i];
		mp[a[i]]++;
	}
	sort(a, a+n);
	vector <ll> v;
    v.push_back(a[0]);
    for(int i=1; i<n;i++){
    	if(a[i] != a[i-1] && mp[a[i]] >= 2)v.push_back(a[i]);
    }

	int cap = v.size();

	ld _min = 99999999999999999.0;
	int l = 0;
	int x, y;
	while(l < cap){
		if(mp[v[l]] >= 4){
			x = y = l;
			break;
		}
		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
			_min = cmp(v[l], v[l+1]);
			x = l;
			y = l+1;
		}
		l++;
	}

	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

}

int main(){
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      	    cout<<"#x "<<x<<"\n";
#define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          	    cout<<"\n";

bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}

const long double PI = 3.1415926535;
const int         mod= 1e9+ 7;

ll n, q;

long double cmp(ll a ,ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
	return (ld)x;
}
void solve(){

	cin >> n;
	ll a[n];
	map <ll, int> m;
	for(int i=0;i<n;i++){
		cin >> a[i];
		m[a[i]]++;
	}
	sort(a, a+n);
	vector <int> v;
	v.pb(a[0]);
	for(int i=1;i<n;i++){
		if(a[i] != a[i-1] && m[a[i]] >= 2)v.pb(a[i]);
	}
	int cap = v.size();
	int l = 0;
        ld _min = 999999999999999999.0;
	int x, y;
	while(l<cap){
              if(m[a[l]] >= 4 && cmp(v[l],v[l]) < _min){
		      _min = cmp(v[l],v[l]);
		      x = l, y =l;
	      }
	      if(l+1 < cap && m[a[l]] >= 4 && cmp(v[l+1], v[l+1] < _min)){
		      _min = cmp(v[l+1],v[l+1]);
		      x = l+1, y = l+1;
	      }
	      if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
		      _min = cmp(v[l],v[l+1]);
		      x = l;
		      y = l+1;
	      }
	      l++;

        }

	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

}
int main(){
	int t;
        cin >> t;
	while(t--){
		solve();
	}
		return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      	    cout<<"#x "<<x<<"\n";
#define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          	    cout<<"\n";

bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}

const long double PI = 3.1415926535;
const int         mod= 1e9+ 7;

ll n, q;

long double cmp(ll a ,ll b){
	ld x = 4*((ld)a/b + (ld)b/a) + 8;
//	cout<<a<<" "<<b<<" "<<x<<"\n";
	return (ld)x;
}
void solve(){
	IOS;
     cin >> n;
     ll a[n];
     for(int i=0;i<n;i++)cin >> a[i];
     sort(a, a+ n);
     map <ll,int> m;
     for(int i= 0;i<n;i++){
	     m[a[i]]++;
     }
     set <ll> s;
     for(int i=0;i<n;i++)s.insert(a[i]);
     vector <ll> arr;
     for(auto it = s.begin(); it != s.end(); it++){
	    if(m[*it] >= 2)
	    arr.push_back(*it);
     }
     int sz =arr.size();
     int l = 0, r =sz-1;
     int v1, v2;
     ld k = LONG_MAX;
//     for(int i=0;i<sz;i++)cout<<arr[i]<<" ";
  //   cn;
     while(l < sz){

	       if(m[arr[l]] >= 4 && cmp(arr[l],arr[l]) < k){
		       k = min(k,cmp(arr[l], arr[l]));
		       v1 = l;
		       v2 = l;
	       }
	       if(l + 1 < sz && m[arr[l+1]]  >= 4 && cmp(arr[l+1],arr[l+1]) < k){
		       k = min(cmp(arr[l+1], arr[l+1]),k);
		       v1 = l+1;
		       v2 = l+1;
	       }
	       if(l+1 < sz && cmp(arr[l],arr[l+1]) < k){
		       k = cmp(arr[l], arr[l+1]);
		       v1 = l;
		       v2 = l+1;
	       }

               l++;
     }
     cout<<arr[v1]<<" "<<arr[v1]<<" "<<arr[v2]<<" "<<arr[v2]<<"\n";

}
int main(){
	int t;
        cin >> t;
	while(t--){
		solve();
	}
		return 0;
}


    #include <bits/stdc++.h>
    using namespace std;

    #define ll long long
    #define ld long double
     int freq[10001];
     ll a[1000001];
    ld cmp(ll a, ll b){
    	ld x = (ld)a/b + (ld)b/a;
    	return x;
    }

    void solve(){
    	int n;
    	cin >> n;

    	memset(freq,0,sizeof(freq));
    	for(int i =0;i<n;i++){
    		cin >> a[i];
    		freq[a[i]]++;
    	}
    	sort(a, a+n);
    	vector <ll> v;
        if(freq[a[0]] >= 2)v.push_back(a[0]);
        for(int i=1; i<n;i++){
        	if(a[i] != a[i-1] && freq[a[i]] >= 2)v.push_back(a[i]);
        }

    	int cap = v.size();

    	ld _min = 1e18;
    	int l = 0;
    	int x, y;
    	while(l < cap){
    		if(freq[v[l]] >= 4){
    			x = y = l;
    			break;
    		}
    		if(l+1 < cap && cmp(v[l], v[l+1]) < _min){
    			_min = cmp(v[l], v[l+1]);
    			x = l;
    			y = l+1;
    		}
    		l++;
    	}
    	// cout<<_min<<"\n";
    	cout<<v[x]<<" "<<v[x]<<" "<<v[y]<<" "<<v[y]<<"\n";

    }

    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
    	cout.tie(NULL);
    	int t;
    	cin >> t;
    	while(t--){
    		solve();
    	}
    	return 0;
    }


#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back

using namespace std;
int a[10001];
int main(){

	int t;
	scanf("%d",&t);

	while (t--) {

	int n;
	scanf("%d",&n);

	vector<int> v;
	memset(a, 0,sizeof(a));
	int flag=0;
	for(int i=0;i<n;i++){
		int r;
		scanf("%d",&r);
		a[r]++;
		if(a[r]==2)v.pb(r);
		if(a[r]>=4)flag=r;
	}
		int x,y;
			float p;
	if(flag!=0){
	//	cout << flag << " " <<flag<<" "<<flag << " "<<flag<<endl;
		printf("%d %d %d %d \n", flag, flag, flag, flag);
		continue;
	}

		sort(v.begin(),v.end());

		float mini=FLT_MAX;
		for(int i=1;i<v.size();i++){
		for(int j=0;j<i;j++){
			p= v[i]/float(v[j]) + v[j]/float(v[i]);
			if(p<mini){
				mini=p;
				x=v[i];
				y=v[j];
			}
		}
}
//cout << x << " " <<x << " " << y << " " << y <<endl;
printf("%d %d %d %d \n",x,x,y,y);
//
//c
////	for(int j=0;j<v.size();j++)cout << v[j] <<" ";
//	int x,y;
//
//	float p;
////	float a;
//	float max=99999999;
//
//// 	cout <<endl;
//	for(int i=1;i<v.size();i++){
//		for(int j=0;j<i;j++){
//			if(v[i]>v[j]) p= v[i]/v[j];
//			else p= v[j]/v[i];
//			if(p < max){
//			max= p;
//			x=v[i];
//			y=v[j];
//		}
//		}
//	}
//
//
//
//
//	}
//
//
}
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back

using namespace std;
int main(){

	int t;
	scanf("%d",&t);

	while (t--) {
	//	cout <<"hya"<<endl;
	int n;
	scanf("%d",&n);

	int a[10001];
	vector<int> v;
	memset(a, 0,sizeof(a));
	int flag=0;
	for(int i=0;i<n;i++){
		int r;
		scanf("%d",&r);
		a[r]++;
		if(a[r]==2)v.pb(r);
		if(a[r]>=4)flag=r;
	}
		int x,y;
			float p;
	if(flag!=0){
	//	cout << flag << " " <<flag<<" "<<flag << " "<<flag<<endl;
		printf("%d %d %d %d \n", flag, flag, flag, flag);
		continue;
	}

		sort(v.begin(),v.end());

		float mini=FLT_MAX;
		for(int i=1;i<v.size();i++){
		for(int j=0;j<i;j++){
			p= v[i]/float(v[j]) + v[j]/float(v[i]);
			if(p<mini){
				mini=p;
				x=v[i];
				y=v[j];
			}
		}
}
//cout << x << " " <<x << " " << y << " " << y <<endl;
printf("%d %d %d %d \n",x,x,y,y);
//
//c
////	for(int j=0;j<v.size();j++)cout << v[j] <<" ";
//	int x,y;
//
//	float p;
////	float a;
//	float max=99999999;
//
//// 	cout <<endl;
//	for(int i=1;i<v.size();i++){
//		for(int j=0;j<i;j++){
//			if(v[i]>v[j]) p= v[i]/v[j];
//			else p= v[j]/v[i];
//			if(p < max){
//			max= p;
//			x=v[i];
//			y=v[j];
//		}
//		}
//	}
//
//
//
//
//	}
//
//
}
    return 0;
}


#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb push_back

using namespace std;
int a[10001];
int main(){

	int t;
	scanf("%d",&t);

	while (t--) {

	int n;
	scanf("%d",&n);

	vector<int> v;
	memset(a, 0,sizeof(a));
	int flag=0;
	for(int i=0;i<n;i++){
		int r;
		scanf("%d",&r);
		a[r]++;
		if(a[r]==2)v.pb(r);
		if(a[r]>=4)flag=r;
	}
		int x,y;
			float p;
	if(flag!=0){
	//	cout << flag << " " <<flag<<" "<<flag << " "<<flag<<endl;
		printf("%d %d %d %d \n", flag, flag, flag, flag);
		continue;
	}

		sort(v.begin(),v.end());

		float mini=FLT_MAX;
		int m=v.size();
		for(int i=1;i<m;i++){
			p= v[i]*1.0/float(v[i-1]) + v[i-1]*1.0/float(v[i]);
			if(p<mini){
				mini=p;
				x=v[i];
				y=v[i-1];

		}
}
//cout << x << " " <<x << " " << y << " " << y <<endl;
printf("%d %d %d %d \n",x,x,y,y);
//
//c
////	for(int j=0;j<v.size();j++)cout << v[j] <<" ";
//	int x,y;
//
//	float p;
////	float a;
//	float max=99999999;
//
//// 	cout <<endl;
//	for(int i=1;i<v.size();i++){
//		for(int j=0;j<i;j++){
//			if(v[i]>v[j]) p= v[i]/v[j];
//			else p= v[j]/v[i];
//			if(p < max){
//			max= p;
//			x=v[i];
//			y=v[j];
//		}
//		}
//	}
//
//
//
//
//	}
//
//
}
    return 0;
}