LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDE
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 Find
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 DPTree DPBitmask DPDigit 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

Barcode Check

Super EasyProblem #17
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

The store list is already sorted - use that.

A store sells many kinds of products and their barcodes are known, given as a sorted list. A manufacturer delivers a list of barcodes of its own products, in no particular order. Your task is to determine how many of the manufacturer's products are already sold in the store.

Input

The first line contains a single integer t - the number of testcases.

  • The first line of each testcase contains two integers n and q - the number of products in the store and the number of the manufacturer's products.
  • The next line contains n integers in increasing order - the barcodes of the products in the store.
  • The next line contains q integers - the barcodes of the manufacturer's products.

Output

For every testcase print a single line with the number of the manufacturer's barcodes that appear on the store's list.

Example

Input
1
5 5
1 3 5 6 7
2 3 4 5 8
Output
2

Of the manufacturer's barcodes, only 3 and 5 appear on the store's list.

Constraints

1≤t≤1000
1≤n,q≤2⋅105
1≤ai​≤109
Both the sum of n and the sum of q over all testcases are at most 2⋅105.


This problem was adapted, with permission, from Provera bar-kodova, 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