Help- Solution logic and code snippet needed

Given an array A, consisting of N distinct integers, and another array B consisting M integers (not necessarily distinct). You need to find the minimum number of elements to be added in B so that A becomes sub-sequence of B, we can add elements at any position in array B.

We define array A elements are distinct if Ai != Bi , i!=j, 1<=i,j<=N (consider 1-based indexing)

Input
T no. of test cases are there and
array A and array B are given with their lengths in each test case

Constraints
1<=T<=10
1<=N,M<=10^5
1<=Ai,Bi<=10^9 (1<=i<=N)

Sample test case:
1 (T)
5 6 (N M)
1 2 3 4 5 (array A)
2 5 6 4 9 12 (array B)
Output= 3

Time limit: 5 seconds
MEmory limit: 256 MB
Source limit: 1024 KB

Please give me logic and code snippet for this problem. Thanks in advance !