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 PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
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

The Most Popular Site

Super EasyProblem #51
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

You never actually have to store the graph.

An agency decided to measure how popular the websites in a network are. Every site can hold links to other sites. A link from a site to itself is ignored - a site is not allowed to make itself popular.

The popularity of a site is the number of links leading to it minus the number of links leading out of it.

Your task is to find the most popular site. If several sites share the highest popularity, report the one with the smallest number.

Input

First line of input will be a single integer t - the number of testcases.
First line of each testcase contains two integers n and m - the number of sites and the number of links. The sites are numbered 1 to n.
In the next m lines will be two integers u and v - a link leading from site u to site v. The same pair may appear more than once, and every occurrence counts as its own link.

Output

For every testcase print a single line with two integers - the number of the most popular site and its popularity.

Example

Input
1
4 9
1 2
1 4
2 1
2 2
2 4
3 2
3 4
4 1
4 4
Output
4 2

Three links lead to site 4 (from 1, 2 and 3) and one leads out of it (to 1), so its popularity is 3−1=2. The self-links 2→2 and 4→4 count for nothing. Sites 1 and 2 end at 0 and site 3 at −2, so nobody beats site 4.

Constraints

1≤t≤1000
1≤n≤105
0≤m≤105
1≤u,v≤n
the sum of n over all testcases does not exceed 2⋅105
the sum of m over all testcases does not exceed 105


This problem was adapted, with permission, from Najpopularniji sajt, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit