LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition RuleMultiplication RuleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsCross and Dot ProductLinesPolygonsPoints and PolygonsConvex Hull
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Strong Pairs

MediumProblem #37
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

A workshop has n sensors lying on a table, and the i-th of them has an id ai​. Two sensors can be linked together only if they are strong together, which the manual defines like this: sensors i and j form a strong pair when

ai​&aj​≥ai​⊕aj​

where & denotes the bitwise AND operation and ⊕ denotes the bitwise XOR operation.

Count how many strong pairs (i,j) with i<j there are. Two sensors lying at different places on the table are always a different pair, even when they happen to carry the same id.

Input

First line of input will be a single integer t - the number of testcases.
Each testcase takes two lines. The first line has a single integer n - the number of sensors. The second line has n integers a1​,a2​,…,an​ - their ids.

Output

For every testcase print a single line with the number of strong pairs.

Example

Input
3
5
1 4 3 7 10
4
6 2 5 3
2
2 4
Output
1
2
0

In the first testcase the only strong pair is (4,7), because 4&7=4 while 4⊕7=3. In the third testcase 2&4=0 and 2⊕4=6, so that pair is not strong and the answer is 0.

Constraints

1≤t≤10
1≤n≤105
1≤ai​≤109
The sum of n over all testcases does not exceed 105.


This problem was adapted from Rock and Lever, problem B of Codeforces Round 672 (Div. 2).

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit