Help me in solving TRIO problem

My issue

Can someone read my code and tell me that how can I avoid duplicate output like(2,6) and (6,2).

My code

import java.util.Scanner;
import java.lang.Math;
import java.io.*;

class Codechef
{
    public static void main(String[] args) throws java.lang.Exception
    {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int a = 0, b = 0, c = 0, count = 0;
            int arr[] = new int[n];
            for (int j = 0; j < n; j++) {
                arr[j] = sc.nextInt();
            }
            for (int x = 0; x < n - 1; x++) {
                for (int k = x + 1; k < n; k++) {
                    a = Math.abs(arr[x] - arr[k]);
                    b = arr[x] + arr[k];
                    c = arr[x] * arr[k];
                    int p = Math.abs(b - a);
                    int q = Math.abs(c - b);

                    if (p == q) {
                        count = count + 1;
                    }
                }
            }
            System.out.println(count);
        }

    }
}

Problem Link: Freedom Practice Coding Problem - CodeChef

@pradyumna2andh
plzz refer my c++ code for better understanding of the logic

#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    long long int n;
	    cin>>n;
	    long long int a[n];
	    map<long long int,long long int> mp;
	    long long int ans=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        
	        if(a[i]!=1)
	        {
	            long long int ch=a[i]*3LL;
	            if(ch%(a[i]-1)==0)
	            {
	                ans+=mp[ch/(a[i]-1)];
	            }
	        }
	        mp[a[i]]++;
	    }
	    cout<<ans<<endl;
	}
	return 0;
}