#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n+1)
            p*=2;
        long long int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < 2*p+1; j++)
            order_tree[j]=0;
        int a[n], b[n1];
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        long long int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int m=order[b[j]];
            int x, y;
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma = order[b[j]];

                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
            x=p+order[b[j]]+1;
                y=2*p+1;
                while(x <= y)
                {
                    if(x%2==1)
                    {
                        order_tree[x]++;
                        x++;
                    }
                    if(y%2==0)
                    {
                        order_tree[y]++;
                        y--;
                    }
                    x/=2;
                    y/=2;
                }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order[j]=1000000000;
        int a[n], b[n1];
        for(int j = 0; j < n; j++)
            cin >> a[j];
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
            order[b[j]]=j;
        }
        int sum=0;
        for(int j = 0; j < n1; j++)
        {
            bool found=false;
            int useless=0;
            for(int k = 0; k < n && !found; k++)
            {
                if(a[k]==-1)
                    useless++;
                else if(a[k]==b[j])
                {
                    found=true;
                    a[k]=-1;
                    sum=sum+2*(k-useless)+1;
                }
                else
                {
                    int l=k;
                    while(l > 0 && order[a[l]] < order[a[l-1]])
                    {
                        swap(a[l], a[l-1]);
                    }
                }
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order[j]=1000000000;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        int sum=0;
        for(int j = 0; j < n1; j++)
        {
            sum=sum+2*(order[b[j]])+1;
            //cout << order[b[j]] << ' ' ;
            //cout << sum << '\n';
            int p=0;
            for(int k = j+1; k < n1; k++)
            {
                if(order[b[k]] < order[b[j]])
                {
                    if(p < order[b[j]]){
                        order[b[k]]=p;
                        p++;
                    }
                }
                else
                    order[b[k]]--;
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order[j]=1000000000;
        int a[n], b[n1];
        for(int j = 0; j < n; j++)
            cin >> a[j];
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
            order[b[j]]=j;
        }
        int sum=0;
        for(int j = 0; j < n1; j++)
        {
            bool found=false;
            int useless=0;
            for(int k = 0; k < n && !found; k++)
            {
                if(a[k]==-1)
                    useless++;
                else if(a[k]==b[j])
                {
                    found=true;
                    for(int m = k+1; m < n; m++)
                        swap(a[m], a[m-1]);
                    sum=sum+2*(k-useless)+1;
                }
                else
                {
                    int l=k;
                    while(l > 0 && order[a[l]] < order[a[l-1]])
                    {
                        swap(a[l], a[l-1]);
                    }
                }
            }
        }
        cout << sum << '\n';
    }
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#include<utility>
#include<string>
#include<iomanip>
#include<queue>
#include<cmath>
#include<utility>
#include<set>
#include<cmath>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        int n, n1;
        cin >> n >> n1;
        int p=1;
        while(p <= n)
            p*=2;
        int order_tree[2*p+1];
        int order[n+1];
        for(int j = 0; j < n+1; j++)
            order_tree[j]=0;
        vector<int> a(n), b(n1);
        for(int j = 0; j < n; j++)
        {
            cin >> a[j];
            order[a[j]]=j;
        }
        for(int j = 0; j < n1; j++)
        {
            cin >> b[j];
        }
        long long int sum=0, ma=0;
        for(int j = 0; j < n1; j++)
        {
            int m=order[b[j]];
            if(order[b[j]] < ma)
                sum++;
            else
            {
                ma=max(ma, order[b[j]]);
                int x, y;
                x=p+order[b[j]]+1;
                y=2*p+1;
                while(x <= y)
                {
                    if(x%2==1)
                    {
                        order_tree[x]++;
                        x++;
                    }
                    if(y%2==0)
                    {
                        order_tree[y]++;
                        y--;
                    }
                    x/=2;
                    y/=2;
                }
                x=(p+order[b[j]])/2;
                while(x >= 1)
                {
                    m-=order_tree[x];
                    x/=2;
                }
                sum=sum+2*m+1;
            }
        }
        cout << sum << '\n';
    }
}


#include<bits/stdc++.h>
# define ll long long
# define pb push_back
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int pos[1000000]={0};

        ll n,m;
        cin>>n>>m;
        ll a[n+1],b[m+1];
        for(ll i=1;i<=n;i++){
            cin>>a[i];
            pos[a[i]]=i;
        }
        for(ll i=1;i<=m;i++){
            cin>>b[i];
        }
        ll ans=0;

        ll ptr=1;
        ll k=0;
        while(ptr<=m){
            ans+=2*(pos[b[ptr]]-k-1)+1;
            k++;
            ll ptr2=ptr+1;
            while(ptr2<=m){
                if(pos[b[ptr2]]<pos[b[ptr]]){
                    ans++;
                    k++;

                }
                else{
                    ptr2--;
                    break;
                }
                ptr2++;

            }
            ptr=ptr2;

        }
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
# define ll long long
# define pb push_back
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){

        ll n,m;
        cin>>n>>m;
        ll a[n+1],b[m+1];
        for(ll i=1;i<=n;i++){
            cin>>a[i];
            pos[a[i]]=i;
        }
        for(ll i=1;i<=m;i++){
            cin>>b[i];
        }
        ll ans=0;

        ll ptr=1;
        ll k=0;
        while(ptr<=m){
            ans+=2*(pos[b[ptr]]-k-1)+1;
            k++;
            ll ptr2=ptr+1;
            while(ptr2<=m){
                if(pos[b[ptr2]]<pos[b[ptr]]){
                    ans++;
                    k++;

                }
                else{
                    ptr2--;
                    break;
                }
                ptr2++;

            }
            ptr=ptr2;

        }
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
# define ll long long
# define pb push_back
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int vis[1000000]={0};
        int pos[1000000]={0};
        int n,m;
        cin>>n>>m;
        int a[n+1],b[m+1];
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin>>b[i];
        }
        int ans=0;

        int ptr2=1;

        while(ptr2<=m){
            int key=b[ptr2];
            // cout<<key<<endl;
            int k=0;
            for(int i=1;i<=n;i++){
                if(a[i]!=key ){
                    if(!vis[a[i]]){
                    k++;
                    pos[a[i]]=1;
                    }

                }
                else{
                    ans+=2*k+1;
                    // cout<<ans<<endl;
                    vis[key]=1;
                    break;
                }
            }

        ptr2++;
        if(ptr2>m){
            break;
        }
        while(true){
            int g=b[ptr2];
            // cout<<g<<endl;
            if(pos[g]){
                ans++;
                // cout<<ans<<"s"<<endl;
                vis[g]=1;
                ptr2++;

            }
            else{
                break;
            }
            if(ptr2>m){
                break;
            }

        }
        }
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
# define ll long long
# define pb push_back
using namespace std;

int main(){
    ll t;
    cin>>t;

    while(t--){
        // int vis[1000000]={0};
        ll pos[1000000]={0};
        ll n,m;
        cin>>n>>m;
        ll a[n+1],b[m+1];
        for(ll i=1;i<=n;i++){
            cin>>a[i];
            pos[a[i]]=i;
        }
        for(ll i=1;i<=m;i++){
            cin>>b[i];
        }
        ll ans=0;

        ll ptr=1;
        ll k=0;
        while(ptr<=m){
            ans+=2*(pos[b[ptr]]-k-1)+1;
            k++;
            ll ptr2=ptr+1;
            while(ptr2<=m){
                if(pos[b[ptr2]]<pos[b[ptr]]){
                    ans++;
                    k++;
                    ptr2++;
                }
                else{
                    break;
                }

            }
            ptr=ptr2;

        }
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
# define ll long long
# define pb push_back
using namespace std;

int main(){
    int t;
    cin>>t;

    while(t--){
        int vis[1000000]={0};
        int pos[1000000]={0};
        int n,m;
        cin>>n>>m;
        int a[n+1],b[m+1];
        for(int i=1;i<=n;i++){
            cin>>a[i];
            pos[a[i]]=i;
        }
        for(int i=1;i<=m;i++){
            cin>>b[i];
        }
        int ans=0;

        int ptr=1;
        int k=0;
        while(ptr<=m){
            ans+=2*(pos[b[ptr]]-k-1)+1;
            k++;
            int ptr2=ptr+1;
            while(ptr2<=m){
                if(pos[b[ptr2]]<pos[b[ptr]]){
                    ans++;
                    k++;
                    ptr2++;
                }
                else{
                    break;
                }

            }
            ptr=ptr2;

        }
        cout<<ans<<endl;
    }

}


//#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define lc root+root
#define rc root+root+1
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define mp make_pair
#define Mid ((left+right)/2)
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define ps(x) printf("%s",x)
#define nl printf("\n")
int main()
{
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//Read the question properly
    int t;
    sd(t);
    while(t--) {

        int n,m;
        sd(n);
        sd(m);

        int a[n],b[m];
        for(int i=0;i<n;++i) sd(a[i]);
        bool appeared[1000009] ={0};
        int obj;
        ll currentI = 0,ans=0,picked=0;
        while(m--) {
            sd(obj);
            if(appeared[obj]) {
                ++ans;
                ++picked;
                }
            else {
                while(currentI < n) {
                    appeared[a[currentI]] = 1;
                    if(a[currentI] == obj) {
                        ans +=  (2 * ( currentI - picked) + 1);
                        ++picked;
                        ++currentI;
                        break;
                    }
                    ++currentI;
                }
            }
        }
        plld(ans);
        nl;
    }
}


//#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define lc root+root
#define rc root+root+1
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define mp make_pair
#define Mid ((left+right)/2)
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define ps(x) printf("%s",x)
#define nl printf("\n")
int main()
{
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//Read the question properly
    int t;
    sd(t);
    while(t--) {

        int n,m;
        sd(n);
        sd(m);

        int a[n],b[m];
        for(int i=0;i<n;++i) sd(a[i]);
        bool appeared[100009] ={0};
        int obj;
        int currentI = 0,ans=0,picked=0;
        while(m--) {
            sd(obj);
            if(appeared[obj]) {
                ++ans;
                ++picked;
                }
            else {
                while(currentI < n) {
                    appeared[currentI] = 1;
                    if(a[currentI] == obj) {
                        ans +=  (2 * ( currentI - picked) + 1);
                        ++picked;
                        ++currentI;
                        break;
                    }
                    ++currentI;
                }
            }
        }
        pd(ans);
        nl;
    }
}


//#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define lc root+root
#define rc root+root+1
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define mp make_pair
#define Mid ((left+right)/2)
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define ps(x) printf("%s",x)
#define nl printf("\n")
int main()
{
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//Read the question properly
    int t;
    sd(t);
    while(t--) {

        int n,m;
        sd(n);
        sd(m);

        int a[n],b[m];
        for(int i=0;i<n;++i) sd(a[i]);
        bool appeared[1000009] ={0};
        int obj;
        ll currentI = 0,ans=0,picked=0;
        while(m--) {
            sd(obj);
            if(appeared[obj]) {
                ++ans;
                ++picked;
                }
            else {
                while(currentI < n) {
                    appeared[a[currentI]] = 1;
                    if(a[currentI] == obj) {
                        ans +=  (2 * ( currentI - picked) + 1);
                        ++picked;
                        ++currentI;
                        break;
                    }
                    ++currentI;
                }
            }
        }
        pd(ans);
        nl;
    }
}


//#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define lc root+root
#define rc root+root+1
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define mp make_pair
#define Mid ((left+right)/2)
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define ps(x) printf("%s",x)
#define nl printf("\n")
int main()
{
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//Read the question properly
    int t;
    sd(t);
    while(t--) {

        int n,m;
        sd(n);
        sd(m);

        int a[n],b[m];
        for(int i=0;i<n;++i) sd(a[i]);
        bool appeared[100009] ={0};
        int obj;
        int currentI = 0,ans=0,picked=0;
        while(m--) {
            sd(obj);
            if(appeared[obj]) {
                ++ans;
                ++picked;
                }
            else {
                while(currentI < n) {
                    appeared[a[currentI]] = 1;
                    if(a[currentI] == obj) {
                        ans +=  (2 * ( currentI - picked) + 1);
                        ++picked;
                        ++currentI;
                        break;
                    }
                    ++currentI;
                }
            }
        }
        pd(ans);
        nl;
    }
}


//#include <ext/pb_ds/assoc_container.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define lc root+root
#define rc root+root+1
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define mp make_pair
#define Mid ((left+right)/2)
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define ss(x) scanf("%s",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define ps(x) printf("%s",x)
#define nl printf("\n")
int main()
{
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//Read the question properly
    int t;
    sd(t);
    while(t--) {

        int n,m;
        sd(n);
        sd(m);

        int a[n],b[m];
        for(int i=0;i<n;++i) sd(a[i]);
        bool appeared[100009] ={0};
        int obj;
        ll currentI = 0,ans=0,picked=0;
        while(m--) {
            sd(obj);
            if(appeared[obj]) {
                ++ans;
                ++picked;
                }
            else {
                while(currentI < n) {
                    appeared[a[currentI]] = 1;
                    if(a[currentI] == obj) {
                        ans +=  (2 * ( currentI - picked) + 1);
                        ++picked;
                        ++currentI;
                        break;
                    }
                    ++currentI;
                }
            }
        }
        pd(ans);
        nl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int a[n];
		map<int,int> h;
		for(int i=0;i<n;i++)
		{
		cin>>a[i];
		h[a[i]] = i;
	    }
		int b[m];

		for(int i=0;i<m;i++)
		{
			cin>>b[i];
		}

		int max_till = 0;

		long long int ans = 0;

		for(int i=0;i<m;i++)
		{
			if(i==0)
			{
				ans = ans + (2*h[b[i]])+1;

				max_till = h[b[i]];

			}
			else
			{
				if(h[b[i]]<max_till)
				{
				ans = ans+1;
			    }
				else
				{
					max_till = h[b[i]];

					int count = 0;

					for(int j=0;j<i;j++)
					{
						if(h[b[j]]<h[b[i]])
						count++;
					}
					int r = h[b[i]]-count;

					ans = ans+(2*r+1);
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int h[100002];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int a[n];
		memset(h,0,sizeof(h));
		for(int i=0;i<n;i++)
		{
		cin>>a[i];
		h[a[i]] = i;
	    }
		int b[m];

		for(int i=0;i<m;i++)
		{
			cin>>b[i];
		}

		int max_till = 0;

		long long int ans = 0;

		for(int i=0;i<m;i++)
		{
			if(i==0)
			{
				ans = ans + (2*h[b[i]])+1;

				max_till = h[b[i]];

			}
			else
			{
				if(h[b[i]]<max_till)
				{
				ans = ans+1;
			    }
				else
				{
					max_till = h[b[i]];

					int count = 0;

					for(int j=0;j<i;j++)
					{
						if(h[b[j]]<h[b[i]])
						count++;
					}
					int r = h[b[i]]-count;

					ans = ans+(2*r+1);
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int h[100001];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int a[n];
		memset(h,0,sizeof(h));
		for(int i=0;i<n;i++)
		{
		cin>>a[i];
		h[a[i]] = i;
	    }
		int b[m];

		for(int i=0;i<m;i++)
		{
			cin>>b[i];
		}

		int max_till = 0;

		long long int ans = 0;

		for(int i=0;i<m;i++)
		{
			if(i==0)
			{
				ans = ans + (2*h[b[i]])+1;

				max_till = h[b[i]];

			}
			else
			{
				if(h[b[i]]<max_till)
				{
				ans = ans+1;
			    }
				else
				{
					max_till = h[b[i]];

					int count = 0;

					for(int j=0;j<i;j++)
					{
						if(h[b[j]]<h[b[i]])
						count++;
					}
					int r = h[b[i]]-count;

					ans = ans+(2*r+1);
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int h[100003];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int a[n];
		memset(h,0,sizeof(h));
		for(int i=0;i<n;i++)
		{
		cin>>a[i];
		h[a[i]] = i;
	    }
		int b[m];

		for(int i=0;i<m;i++)
		{
			cin>>b[i];
		}

		int max_till = 0;

		long long int ans = 0;

		for(int i=0;i<m;i++)
		{
			if(i==0)
			{
				ans = ans + (2*h[b[i]])+1;

				max_till = h[b[i]];

			}
			else
			{
				if(h[b[i]]<max_till)
				{
				ans = ans+1;
			    }
				else
				{
					max_till = h[b[i]];

					int count = 0;

					for(int j=0;j<i;j++)
					{
						if(h[b[j]]<h[b[i]])
						count++;
					}
					int r = h[b[i]]-count;

					ans = ans+(2*r+1);
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int h[100003];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m;
		cin>>n>>m;
		int a[n];
		memset(h,0,sizeof(h));
		for(int i=0;i<n;i++)
		{
		cin>>a[i];
		h[a[i]] = i;
	    }
		int b[m];

		for(int i=0;i<m;i++)
		{
			cin>>b[i];
		}

		int max_till = 0;

		long long int ans = 0;

		for(int i=0;i<m;i++)
		{
			if(i==0)
			{
				ans = ans + (2*h[b[i]])+1;

				max_till = h[b[i]];

			}
			else
			{
				if(h[b[i]]<max_till)
				{
				ans = ans+1;
			    }
				else
				{
					max_till = h[b[i]];

					int count = h[b[i]]-i;

					ans = ans+(2*count+1);
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n), b(m);
    // set<int> mp;

    rng(i, 0, n)
        cin >> a[i];
    rng(i,0,m){
        cin >> b[i];
        // mp.insert(b[i]);
    }

    int res = 0, j = 0, cnt = 0;
    for(int i= 0; i<m ; ){
        int curr = b[i];
        i++;

        while(a[j] != curr && j<n){
            if(a[j] == b[i]){
                res++;
                i++;
                cnt++;
            }
            j++;

        }
        j++;
        cnt++;
        res += 2*(j-cnt) + 1;
    }
    cout<<res<<endl;
}

int main() {
    fastio
    int t;
    cin>>t;
    while(t--){
        test_case();
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n), b(m);
    // set<int> mp;

    rng(i, 0, n)
        cin >> a[i];
    rng(i,0,m){
        cin >> b[i];
        // mp.insert(b[i]);
    }

    int j = 0, cnt = 0;
    long long res = 0;
    for(int i= 0; i<m ; ){
        int curr = b[i];
        i++;
        int c = 0;
        while(a[j] != curr && j<n ){
            if(a[j] == b[i] && i<m){
                res++;
                i++;
                c++;
            }
            j++;
        }
        j++;
        cnt++;
        res += 2*(j-cnt) + 1;
        cnt += c;
    }
    cout<<res<<endl;
}

int main() {
    fastio
    int t;
    cin>>t;
    while(t--){
        test_case();
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n), b(m);
    set<int> mp;

    rng(i, 0, n)
        cin >> a[i];
    rng(i,0,m){
        cin >> b[i];
        // mp.insert(b[i]);
    }

    int j = 0, cnt = 0;
    long long res = 0;
    for(int i= 0; i<m ; ){
        int curr = b[i];
        i++;
        int c = 0;
        while(j<n && a[j] != curr ){
            mp.insert(a[j]);
            j++;
        }
        while(mp.count(b[i])){
        	res++;
        	c++;
        	i++;
        }

        j++;
        cnt++;
        res += 2*(j-cnt) + 1;
        cnt += c;
    }
    cout<<res<<endl;
}

int main() {
    fastio
    int t;
    cin>>t;
    while(t--){
        test_case();
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n), b(m);
    // set<int> mp;

    rng(i, 0, n)
        cin >> a[i];
    rng(i,0,m){
        cin >> b[i];
        // mp.insert(b[i]);
    }

    int res = 0, j = 0, cnt = 0;
    for(int i= 0; i<m ; ){
        int curr = b[i];
        i++;
        int c = 0;
        while(a[j] != curr && j<n ){
            if(a[j] == b[i] && i<m){
                res++;
                i++;
                c++;
            }
            j++;
        }
        j++;
        cnt++;
        res += 2*(j-cnt) + 1;
        cnt += c;
    }
    cout<<res<<endl;
}

int main() {
    fastio
    int t;
    cin>>t;
    while(t--){
        test_case();
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n), b(m);
    set<int> mp;

    rng(i, 0, n)
        cin >> a[i];
    rng(i,0,m){
        cin >> b[i];
        // mp.insert(b[i]);
    }

    int j = 0, cnt = 0;
    long long res = 0;
    for(int i= 0; i<m ; ){
        int curr = b[i];
        i++;
        int c = 0;
        while(j<n && a[j] != curr ){
            mp.insert(a[j]);
            j++;
        }
        while(i < m && mp.count(b[i])){
        	res++;
        	c++;
        	i++;
        }

        j++;
        cnt++;
        res += 2*(j-cnt) + 1;
        cnt += c;
    }
    cout<<res<<endl;
}

int main() {
    fastio
    int t;
    cin>>t;
    while(t--){
        test_case();
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n), b(m);
    set<int> mp;

    rng(i, 0, n)
        cin >> a[i];
    rng(i,0,m){
        cin >> b[i];
        mp.insert(b[i]);
    }

    int res = 0, j = 0, cnt = 0;
    for(int i= 0; i<m ; ){
        int curr = b[i];
        i++;
        cnt = 0;
        while(a[j] != curr && j<n){
            if(a[j] == b[i]){
                res++;
                i++;
            }
            j++;
            cnt++;
        }
        j++;
        res += 2*cnt + 1;
    }
    cout<<res<<endl;
}

int main() {
    fastio
    int t;
    cin>>t;
    while(t--){
        test_case();
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    int m, n;
    cin >> n >> m;
    vector<int> a(n), b(m);
    // set<int> mp;

    rng(i, 0, n)
        cin >> a[i];
    rng(i,0,m){
        cin >> b[i];
        // mp.insert(b[i]);
    }

    int j = 0, cnt = 0;
    long long res = 0;
    for(int i= 0; i<m ; ){
        int curr = b[i];
        i++;
        int c = 0;
        while(j<n && a[j] != curr ){
            if(i<m && a[j] == b[i]){
                res++;
                i++;
                c++;
            }
            j++;
        }
        j++;
        cnt++;
        res += 2*(j-cnt) + 1;
        cnt += c;
    }
    cout<<res<<endl;
}

int main() {
    fastio
    int t;
    cin>>t;
    while(t--){
        test_case();
    }

	return 0;
}


#include <bits/stdc++.h>
#define MAX 100'005
using namespace std;

long long b[MAX];

int main(){
    queue<long long> qu;
    cin.sync_with_stdio(0);
    cin.tie(0);
    long long t,n,m,i,j,aux,k;
    bitset<MAX> bt;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(!bt[b[i]]){
                while(!qu.empty() && qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    k+=2;
                }
                qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 1'000'005
using namespace std;

long long b[MAX];

int main(){
    queue<long long> qu;
    cin.sync_with_stdio(0);
    cin.tie(0);
    long long t,n,m,i,j,aux,k;
    bitset<MAX> bt;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(!bt[b[i]]){
                while(qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    k+=2;
                }
                qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 100'005
using namespace std;

int b[MAX];

int main(){
    queue<int> qu;
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t,n,m,i,j,aux,ins,k;
    bitset<MAX> bt;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        ins = 0;
        k = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(bt[b[i]])
                ins--;
            else
                while(!qu.empty() && qu.front() != b[i]){
                    bt[qu.front()] = true;
                    ins ++;
                    qu.pop();
                    k+=2;
                }
            if(!qu.empty())
                qu.pop();
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 1'000'005
using namespace std;

long long b[MAX];

int main(){
    queue<long long> qu;
    cin.sync_with_stdio(0);
    cin.tie(0);
    long long t,n,m,i,j,aux,ins,k;
    bitset<MAX> bt;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        ins = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(bt[b[i]])
                ins--;
            else{
                k+= 2*ins;
                while(qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    ins++;
                    k+=2;
                }
                qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 100'005
using namespace std;

int b[MAX];

int main(){
    queue<int> qu;
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t,n,m,i,j,aux,ins,k;
    bitset<MAX> bt;
    cin >> t;
    while(t--){
        ins = 0;
        k = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(bt[b[i]])
                ins--;
            else
                while(!qu.empty() && qu.front() != b[i]){
                    bt[qu.front()] = true;
                    ins ++;
                    qu.pop();
                    k+=2;
                }
            if(!qu.empty())
                qu.pop();
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 1000'005
using namespace std;

queue<long long> qu;
bitset<MAX> bt;
long long b[MAX];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    long long t,n,m,i,j,aux,ins,k;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        ins = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(bt[b[i]])
                ins--;
            else{
                while(qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    ins++;
                }
                k+= 2*ins;
                qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 100'005
using namespace std;

queue<long long> qu;
bitset<MAX> bt;
long long b[MAX];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    long long t,n,m,i,j,aux,ins,k;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        ins = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(bt[b[i]])
                ins--;
            else{
                while(qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    ins++;
                }
                k+= 2*ins;
                qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 1000'005
using namespace std;

queue<long long> qu;
bitset<MAX> bt;
long long b[MAX];

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    long long t,n,m,i,j,aux,ins,k;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        ins = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < m; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(bt[b[i]])
                ins--;
            else{
                while(qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    ins++;
                }
                k+= 2*ins;
                qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 100'005
using namespace std;

long long b[MAX];

int main(){
    queue<long long> qu;
    cin.sync_with_stdio(0);
    cin.tie(0);
    int t,n,m,i,j,aux,k;
    bitset<MAX> bt;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(!bt[b[i]]){
                while(!qu.empty() && qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    k+=2;
                }
                qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define MAX 1'000'005
using namespace std;

long long b[MAX];

int main(){
    queue<long long> qu;
    cin.sync_with_stdio(0);
    cin.tie(0);
    long long t,n,m,i,j,aux,ins,k;
    bitset<MAX> bt;
    cin >> t;
    while(t--){
        while(!qu.empty())
            qu.pop();
        k = 0;
        ins = 0;
        cin >> n >> m;
        bt.reset();
        for(i = 0 ; i < n ;i++){
            cin >> aux;
            qu.push(aux);
        }
        for(i = 0; i < n; i++){
            cin >> b[i];
        }
        for(i = 0; i < m;i++){
            if(bt[b[i]])
                ins--;
            else{
                while(!qu.empty() && qu.front() != b[i]){
                    bt[qu.front()] = true;
                    qu.pop();
                    ins++;
                }
                k+= 2*ins;
                if(!qu.empty())
                    qu.pop();
            }
            k++;
        }
        cout << k <<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
#include<set>
#include<string>
#include<climits>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define mk(name,n,ty) ty* name=new ty[n];
typedef long long int ll;
const int MAX_N=100;
int main(){
	test{
    int n,m; cin>>n>>m;
    int arr[n+1],list[m+1],pos[n+1];
    for(int i=1;i<=n;i++) {
     cin>>arr[i];
     pos[arr[i]]=i;
      }
    for(int i=1;i<=m;i++) cin>>list[i];
    int last=-1,ans=0;
    for(int i=1;i<=m;i++){
    	if(pos[list[i]]>last){
    		ans+=2*(pos[list[i]]-i);
    		last=pos[list[i]];
    	}
    }
    cout<<ans<<endl;
    }
    return 0;
  }


#include<bits/stdc++.h>
#include<set>
#include<string>
#include<climits>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define mk(name,n,ty) ty* name=new ty[n];
typedef long long int ll;
const int MAX_N=100;
int main(){
	test{
    int n,m; cin>>n>>m;
    int arr[n+1],list[m+1],pos[n+1];
    for(int i=1;i<=n;i++) {
     cin>>arr[i];
     pos[arr[i]]=i;
      }
    for(int i=1;i<=m;i++) cin>>list[i];
    int last=-1,ans=0;
    for(int i=1;i<=m;i++){
    	if(pos[list[i]]>last){
    		ans+=(1+2*(pos[list[i]]-i));
    		last=pos[list[i]];
    	}else{
    		ans+=1;
    		last=1;
    	}
    }
    cout<<ans<<endl;
    }
    return 0;
  }


#include<bits/stdc++.h>
#include<set>
#include<string>
#include<climits>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define mk(name,n,ty) ty* name=new ty[n];
typedef long long int ll;
const int MAX_N=100;
int main(){
	test{
    int n,m; cin>>n>>m;
    int arr[n+1],list[m+1];
    for(int i=1;i<=n;i++) cin>>arr[i];
    for(int i=1;i<=m;i++) cin>>list[i];
    int last=-1,ans=0;
    for(int i=1;i<=m;i++){
    	if(list[i]>last){
    		ans+=(1+2*(arr[list[i]]-i);
    	}else{
    		ans+=1;
    	}
    	last=arr[list[i]]-i;
    }
    cout<<ans<<endl;
    }
    return 0;
  }


#include<bits/stdc++.h>
#include<set>
#include<string>
#include<climits>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define mk(name,n,ty) ty* name=new ty[n];
typedef long long int ll;
const int MAX_N=100;
int main(){
	test{
    int n,m; cin>>n>>m;
    int arr[n+1],list[m+1],pos[n+1];
    for(int i=1;i<=n;i++) {
     cin>>arr[i];
     pos[arr[i]]=i;
      }
    for(int i=1;i<=m;i++) cin>>list[i];
    int last=-1,ans=0;
    for(int i=1;i<=m;i++){
    	if(pos[list[i]]>last){
    		ans+=(1+2*(pos[list[i]]-i));
    		last=pos[list[i]];
    	}else{
    		ans++;
    	}
    }
    cout<<ans<<endl;
    }
    return 0;
  }


#include<bits/stdc++.h>
#include<set>
#include<string>
#include<climits>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define mk(name,n,ty) ty* name=new ty[n];
typedef long long int ll;
const int MAX_N=100;
int main(){
	test{
    int n,m; cin>>n>>m;
    int arr[n+1],list[m+1],pos[n+1];
    for(int i=1;i<=n;i++){
      cin>>arr[i];
      pos[arr[i]]=i;
    }
    for(int i=1;i<=m;i++) cin>>list[i];
    int last=-1,ans=0;
    for(int i=1;i<=m;i++){
    	if(pos[list[i]]>last){
    		ans+=(1+2*(pos[list[i]]-i));
    	}else{
    		ans+=1;
    	}
    	last=pos[list[i]];
    }
    cout<<ans<<endl;
    }
    return 0;
  }


#include<bits/stdc++.h>
#include<set>
#include<string>
#include<climits>
using namespace std;
#define endl "\n"
#define M 1000000007
#define enter ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define pb push_back
#define mp make_pair
#define mk(name,n,ty) ty* name=new ty[n];
typedef long long int ll;
const int MAX_N=100;
int main(){
	test{
    int n,m; cin>>n>>m;
    int arr[n+1],list[m+1];
    for(int i=1;i<=n;i++) cin>>arr[i];
    for(int i=1;i<=m;i++) cin>>list[i];
    int last=-1,ans=0;
    for(int i=1;i<=m;i++){
    	if(list[i]>last){
    		ans+=(1+2*(arr[list[i]]-i));
    	}else{
    		ans+=1;
    	}
    	last=arr[list[i]]-i;
    }
    cout<<ans<<endl;
    }
    return 0;
  }


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n;cin>>n;ll a[n+1];ll m;cin>>m;ll k=0;ll d=0;ll max=-1;ll ans=0;
		for(ll i=1;i<=n;i++)
		{
			cin>>k;
			a[k]=i;
		}
		for(ll i=1;i<=m;i++)
		{
			cin>>k;
			if(a[k]>max)
			{
				max=a[k];
				ans+=1+2*(a[k]-i);
			}
			else
			ans++;
		}
		cout<<ans<<"\n";
	}
}


#include<iostream>
#include<iterator>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,m;
		cin>>n>>m;
		vector<int> v1, v2;
		int c;
		for(int i=0; i<n; i++) {
			cin>>c;
			v1.push_back(c);
		}
		for(int i=0; i<m; i++) {
			cin>>c;
			v2.push_back(c);
		}
		int time = 0;
		int index;
		int i1;
		vector<int>::iterator it;
		int i;
		for(i=0; i<m; ) {
			it = find(v1.begin(), v1.end(), v2[i]);
			index = distance(v1.begin(), it);
			time += 2*index+1;
			int k = 0;
			for(int j = i+1; j<m ;j++) {
				it = find(v1.begin(), v1.end(), v2[j]);
				i1 = distance(v1.begin(), it);
				if(i1<index) {
					swap(v1[k], v1[i1]);
					time += 1;
					k++;
				}
				else
					break;
			}
			i += k+1;
			v1.erase(v1.begin()+index);
		}
		cout<<time<<"\n";
		t--;
	}
	return 0;
}


#include<iostream>
#include<iterator>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,m;
		cin>>n>>m;
		vector<int> v1, v2;
		int c;
		for(int i=0; i<n; i++) {
			cin>>c;
			v1.push_back(c);
		}
		for(int i=0; i<m; i++) {
			cin>>c;
			v2.push_back(c);
		}
		map<int,int> santa;
		int i;
		for(i=0; i<m; i++) {
			santa.insert(pair<int,int>(v2[i], 0));
		}
		int j=0;
		map<int,int>::iterator itr = santa.begin();
		for(int k=0; k<m ; k++) {
			if(santa[v2[k]] == 0) {
				while(v1[j] != v2[k]) {
					santa[v1[j]] = 1;
					j++;
				}
				santa[v1[j]] = 2*(j-k)+1;
				j++;
			}
		}
		long long int time = 0;
		for(int k =0; k<m; k++) {
			time += santa[v2[k]];
		}
		cout<<time<<"\n";
		t--;
	}
	return 0;
}


#include<iostream>
#include<iterator>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,m;
		cin>>n>>m;
		vector<int> v1, v2;
		int c;
		for(int i=0; i<n; i++) {
			cin>>c;
			v1.push_back(c);
		}
		for(int i=0; i<m; i++) {
			cin>>c;
			v2.push_back(c);
		}
		int time = 0;
		int index;
		int i1;
		vector<int>::iterator it;
		for(int i=0; i<m; i++) {
			it = find(v1.begin(), v1.end(), v2[i]);
			index = distance(v1.begin(), it);
			time += 2*index+1;
			if(i+1 < m) {
				it = find(v1.begin(), v1.end(), v2[i+1]);
				i1 = distance(v1.begin(), it);
				if(i1<index )
					swap(v1[0], v1[i1]);
			}
			v1.erase(v1.begin()+index);
		}
		cout<<time<<"\n";
		t--;
	}
	return 0;
}


#include<iostream>
#include<iterator>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,m;
		cin>>n>>m;
		vector<int> v1, v2;
		int c;
		for(int i=0; i<n; i++) {
			cin>>c;
			v1.push_back(c);
		}
		for(int i=0; i<m; i++) {
			cin>>c;
			v2.push_back(c);
		}
		map<int,int> santa;
		int i;
		for(i=0; i<m; i++) {
			santa.insert(pair<int,int>(v2[i], 0));
		}
		int j=0;
		map<int,int>::iterator itr = santa.begin();
		for(int k=0; k<m ; k++) {
			if(santa[v2[k]] == 0) {
				while(v1[j] != v2[k]) {
					santa[v1[j]] = 1;
					j++;
				}
				santa[v1[j]] = 2*(j-k)+1;
				j++;
			}
		}
		int time = 0;
		for(int k =0; k<m; k++) {
			time += santa[v2[k]];
		}
		cout<<time<<"\n";
		t--;
	}
	return 0;
}


#include<iostream>
#include<iterator>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,m;
		cin>>n>>m;
		vector<int> v1, v2;
		int c;
		for(int i=0; i<n; i++) {
			cin>>c;
			v1.push_back(c);
		}
		for(int i=0; i<m; i++) {
			cin>>c;
			v2.push_back(c);
		}
		int time = 0;
		int index;
		int i1;
		vector<int>::iterator it;
		for(int i=0; i<m; i++) {
			it = find(v1.begin(), v1.end(), v2[i]);
			index = distance(v1.begin(), it);
			time += 2*index+1;
			int k = 0;
			for(int j = i+1; j<m ;j++) {
				it = find(v1.begin(), v1.end(), v2[j]);
				i1 = distance(v1.begin(), it);
				if(i1<index) {
					swap(v1[k], v1[i1]);
					k++;
				}
			}
			v1.erase(v1.begin()+index);
		}
		cout<<time<<"\n";
		t--;
	}
	return 0;
}


#include<iostream>
#include<iterator>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,m;
		cin>>n>>m;
		vector<int> v1, v2;
		int c;
		for(int i=0; i<n; i++) {
			cin>>c;
			v1.push_back(c);
		}
		for(int i=0; i<m; i++) {
			cin>>c;
			v2.push_back(c);
		}
		int time = 0;
		int index;
		int i1;
		vector<int>::iterator it;
		for(int i=0; i<m; i++) {
			it = find(v1.begin(), v1.end(), v2[i]);
			index = distance(v1.begin(), it);
			time += 2*index+1;
			int k = 0;
			for(int j = i+1; j<m ;j++) {
				it = find(v1.begin(), v1.end(), v2[j]);
				i1 = distance(v1.begin(), it);
				if(i1<index) {
					swap(v1[k], v1[i1]);
					k++;
				}
				else
					break;
			}
			v1.erase(v1.begin()+index);
		}
		cout<<time<<"\n";
		t--;
	}
	return 0;
}


#include<iostream>
#include<iterator>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t>0) {
		int n,m;
		cin>>n>>m;
		vector<int> v1, v2;
		int c;
		for(int i=0; i<n; i++) {
			cin>>c;
			v1.push_back(c);
		}
		for(int i=0; i<m; i++) {
			cin>>c;
			v2.push_back(c);
		}
		map<int,int> santa;
		int i;
		for(i=0; i<m; i++) {
			santa.insert(pair<int,int>(v2[i], 0));
		}
		int j=0;
		map<int,int>::iterator itr = santa.begin();
		for(int k=0; k<m ; k++) {
			if(santa[v2[k]] == 0) {
				while(v1[j] != v2[k]) {
					santa[v1[j]] = 1;
					j++;
				}
				santa[v1[j]] = 2*(j-k)+1;
				j++;
			}
		}
		long int time = 0;
		for(int k =0; k<m; k++) {
			time += santa[v2[k]];
		}
		cout<<time<<"\n";
		t--;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,j,k;
    cin>>t;
    while(t--){
        int a[1001],b[10001],n,m,mk[1001];
        cin>>n>>m;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mk[a[i]]=i;
        }
        long long ans=0;int id=0;
        for(i=1;i<=m;i++){
            scanf("%d",&b[i]);
            if(mk[b[i]]<id) ans++;
            else{
                ans+=(mk[b[i]]-i)*2+1;
            }
            id=max(mk[b[i]],id);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,j,k;
    cin>>t;
    while(t--){
        int a[1001],b[10001],n,m,mk[1001];
        cin>>n>>m;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mk[a[i]]=i;
        }
        for(i=1;i<=m;i++){
            scanf("%d",&b[i]);
        }
        long long ans=0;int id=0;
        for(i=1;i<=m;i++){
            if(mk[b[i]]<id) ans++;
            else{
                ans+=(mk[b[i]]-i)*2+1;
            }
            id=max(mk[b[i]],id);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,j,k;
    cin>>t;
    while(t--){
        int a[1001],b[10001],n,m,mk[1001];
        cin>>n>>m;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mk[a[i]]=i;
        }
        for(i=1;i<=m;i++){
            scanf("%d",&b[i]);
        }
        ll ans=0;int id=0;
        for(i=1;i<=m;i++){
            if(mk[b[i]]<id) ans++;
            else{
                ans+=(mk[b[i]]-i)*2+1;
            }
            id=max(mk[b[i]],id);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,j,k;
    cin>>t;
    while(t--){
        int a[1001],b[10001],n,m,mk[1001];
        cin>>n>>m;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mk[a[i]]=i;
        }
        long long ans=0;int id=0;
        for(i=1;i<=m;i++){
            scanf("%d",&b[i]);
            if(mk[b[j]]<id) ans++;
            else{
                ans+=(mk[b[i]]-i)*2+1;
            }
            id=max(mk[b[i]],id);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int t,i,j,k;
    cin>>t;
    while(t--){
        int a[1001],b[10001],n,m,mk[1001];
        cin>>n>>m;
        for(i=1;i<=n;i++){
            cin>>a[i];
            mk[a[i]]=i;
        }
        for(i=1;i<=m;i++){
            cin>>b[i];
        }
        ll ans=0;int id=0;
        for(i=1;i<=m;i++){
            if(mk[b[i]]<id) ans++;
            else{
                ans+=(mk[b[i]]-i)*2+1;
            }
            id=max(mk[b[i]],id);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
long long a[100005],b[100005],mk[100005],id,ans,i,t,n,m;
int main()
{
    cin>>t;
    while(t--){
        cin>>n>>m;
        for(i=1;i<=n;i++){
            cin>>a[i];
            mk[a[i]]=i;
        }
        ans=0;id=0;
        for(i=1;i<=m;i++){
            cin>>b[i];
            if(mk[b[i]]<id) ans++;
            else{
                ans+=(mk[b[i]]-i)*2+1;
            }
            id=max(mk[b[i]],id);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,j,k;
    cin>>t;
    while(t--){
        int a[1001],b[10001],n,m,mk[1001];
        cin>>n>>m;
        for(i=1;i<=n;i++){
            scanf("%d",&a[i]);
            mk[a[i]]=i;
        }
        long long ans=0;int id=0;
        for(i=1;i<=m;i++){
            scanf("%d",&b[i]);
            for(i=1;i<=m;i++){
                if(mk[b[i]]<id) ans++;
                else{
                    ans+=(mk[b[i]]-i)*2+1;
                }
                id=max(mk[b[i]],id);
            }
        }
        cout<<ans<<"\n";
    }
}


    #include <iostream>
    #include <bits/stdc++.h>

    using namespace std;

    int main()
    { ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t;
        cin>>t;
        for(int q=0;q<t;q++)
        {
            int n,m;
            cin>>n>>m;
            int ar[n],pos[m];
            for(int i=0;i<n;i++)
            {
                cin>>ar[i];
            }
            for(int i=0;i<m;i++)
            {
                cin>>pos[i];
            }
            set<int> s;
            int cur=0;
            //int d=5000100000;
            long ans=0;
            for(int i=0;i<m;i++)
            {
            int x=pos[i];
               if(s.find(x)!=s.end()){
                ans++;
                s.erase(x);
               }else
               {
               while(ar[cur]!=x){
                s.insert(ar[cur]);
                cur++;

               }
               cur++;
               ans+=(s.size()*2)+1;
               }

            }
            cout<<ans<<endl;
        }

    }


    #include <iostream>
    #include <bits/stdc++.h>

    using namespace std;

    int main()
    { ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t;
        cin>>t;
        for(int q=0;q<t;q++)
        {
            int n,m;
            cin>>n>>m;
            int ar[n],pos[m];
            for(int i=0;i<n;i++)
            {
                cin>>ar[i];
            }
            for(int i=0;i<m;i++)
            {
                cin>>pos[i];
            }
            multiset<int> s;
            int cur=0;
            //int d=5000100000;
            long ans=0;
            for(int i=0;i<m;i++)
            {
            int x=pos[i];
               if(s.find(x)!=s.end()){
                ans++;
                s.erase(s.find(x));
               }else
               {
               while(ar[cur]!=x){
                s.insert(ar[cur]);
                cur++;

               }
               cur++;
               ans+=(s.size()*1L*2)+1L;
               }

            }
            cout<<ans<<endl;
        }

    }


    #include <iostream>
    #include <bits/stdc++.h>

    using namespace std;

    int main()
    { ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t;
        cin>>t;
        for(int q=0;q<t;q++)
        {
            int n,m;
            cin>>n>>m;
            int ar[n],pos[m];
            for(int i=0;i<n;i++)
            {
                cin>>ar[i];
            }
            for(int i=0;i<m;i++)
            {
                cin>>pos[i];
            }
            multiset<int> s;
            int cur=0;
            //int d=5000100000;
            long long ans=0;
            for(int i=0;i<m;i++)
            {
            int x=pos[i];
               if(s.find(x)!=s.end()){
                ans++;
                s.erase(s.find(x));
               }else
               {
               while(ar[cur]!=x){
                s.insert(ar[cur]);
                cur++;

               }
               cur++;
               ans+=(s.size()*1L*2)+1L;
               }

            }
            cout<<ans<<endl;
        }

    }


    #include <iostream>
    #include <bits/stdc++.h>

    using namespace std;

    int main()
    { ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t;
        cin>>t;
        for(int q=0;q<t;q++)
        {
            int n,m;
            cin>>n>>m;
            int ar[n],pos[m];
            for(int i=0;i<n;i++)
            {
                cin>>ar[i];
            }
            for(int i=0;i<m;i++)
            {
                cin>>pos[i];
            }
            set<int> s;
            int cur=0;
            //int d=5000100000;
            long ans=0;
            for(int i=0;i<m;i++)
            {
            int x=pos[i];
               if(s.find(x)!=s.end()){
                ans++;
                s.erase(x);
               }else
               {
               while(ar[cur]!=x){
                s.insert(ar[cur]);
                cur++;

               }
               cur++;
               ans+=(s.size()*1L*2)+1L;
               }

            }
            cout<<ans<<endl;
        }

    }


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int q=0;q<t;q++)
    {
            int n,m;
        cin>>n>>m;
        int ar[n],pos[m];
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
        }
        for(int i=0;i<m;i++)
        {
            cin>>pos[i];
        }
        set<int> s;
        int cur=0;
        int ans=0;
        for(int i=0;i<m;i++)
        {
            int x=pos[i];
           if(s.count(x)){
            ans++;
            s.erase(x);
           }else
           {
           while(ar[cur]!=x){
            s.insert(ar[cur]);
            cur++;

           }
           cur++;
           ans+=s.size()*2+1;
           }

        }
        cout<<ans<<endl;
    }

}


    #include <iostream>
    #include <bits/stdc++.h>

    using namespace std;

    int main()
    { ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t;
        cin>>t;
        for(int q=0;q<t;q++)
        {
            int n,m;
            cin>>n>>m;
            int ar[n],pos[m];
            for(int i=0;i<n;i++)
            {
                cin>>ar[i];
            }
            for(int i=0;i<m;i++)
            {
                cin>>pos[i];
            }
            multiset<int> s;
            int cur=0;
            //int d=5000100000;
            long ans=0;
            for(int i=0;i<m;i++)
            {
            int x=pos[i];
               if(s.find(x)!=s.end()){
                ans++;
                s.erase(x);
               }else
               {
               while(ar[cur]!=x){
                s.insert(ar[cur]);
                cur++;

               }
               cur++;
               ans+=(s.size()*1L*2)+1L;
               }

            }
            cout<<ans<<endl;
        }

    }


    #include <iostream>
    #include <bits/stdc++.h>

    using namespace std;

    int main()
    { ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t;
        cin>>t;
        for(int q=0;q<t;q++)
        {
            int n,m;
            cin>>n>>m;
            int ar[n],pos[m];
            for(int i=0;i<n;i++)
            {
                cin>>ar[i];
            }
            for(int i=0;i<m;i++)
            {
                cin>>pos[i];
            }
            multiset<int> s;
            int cur=0;
            //int d=5000100000;
            long ans=0;
            for(int i=0;i<m;i++)
            {
            int x=pos[i];
            if(!s.empty())
               if(s.find(x)!=s.end()){
                ans++;
                s.erase(s.find(x));
                continue;
                }
              while(ar[cur]!=x){
                s.insert(ar[cur]);
                cur++;

               }
               cur++;
               ans+=(s.size()*1L*2)+1L;

            }
            cout<<ans<<endl;
        }

    }


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{ ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int q=0;q<t;q++)
    {
        int n,m;
        cin>>n>>m;
        int ar[n],pos[m];
        for(int i=0;i<n;i++)
        {
            cin>>ar[i];
        }
        for(int i=0;i<m;i++)
        {
            cin>>pos[i];
        }
        set<int> s;
        int cur=0;
        //int d=5000100000;
        long ans=0;
        for(int i=0;i<m;i++)
        {
            int x=pos[i];
           if(s.count(x)){
            ans++;
            s.erase(x);
           }else
           {
           while(ar[cur]!=x){
            s.insert(ar[cur]);
            cur++;

           }
           cur++;
           ans+=s.size()*2+1;
           }

        }
        cout<<ans<<endl;
    }

}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       int n,m;
       cin>>n>>m;
       int ar[n];
       int br[n];
       for(int i=0;i<n;i++){
        cin>>ar[i];
       }
       for(int i=0;i<m;i++)
       {
           cin>>br[i];
       }
       set<int> has;
       int step=0;
       int pointer=0;
       for(int i=0;i<m;i++)
       {
           int cur=br[i];
           if(has.count(cur)){
            step++;
            continue;
           }

           while(ar[pointer]!=cur){
            has.insert(ar[pointer]);
            pointer++;
           }
           step+=(2*(pointer-i))+1;

       }
       cout<<step<<endl;
   }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       int n,m;
       cin>>n>>m;
       int ar[n];
       int br[n];
       for(int i=0;i<n;i++){
        cin>>ar[i];
       }
       for(int i=0;i<m;i++)
       {
           cin>>br[i];
       }
       set<int> has;
       long long step=0;
       int pointer=0;
       for(int i=0;i<m;i++)
       {
           int cur=br[i];
           if(has.count(cur)){
            step++;
            continue;
           }

           while(ar[pointer]!=cur){
            has.insert(ar[pointer]);
            pointer++;
           }
           has.insert(ar[pointer]);

           step+=(2*1LL*(pointer-i))+1;

       }
       cout<<step<<endl;
   }
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    int t ;
    scanf("%d",&t) ;
    while(t--)
    {
        int n , m ;
        scanf("%d%d",&n,&m) ;
        int a[n+1] , b[m+1] , ind[n+1] = {0} ;
        for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) , ind[a[i]] = i ;
        for(int i = 1 ; i <= m ; ++i) scanf("%d",&b[i]) ;
        int i = 1 , mx = -1 ;
        long long ans = m ;
        for(int i = 1 ; i <= m ; ++i)
        {
            if(ind[b[i]]>mx)
            {
                ans += (2*(ind[b[i]]-i)) ;
                mx = ind[b[i]] ;
            }
        }
        printf("%lld\n",ans) ;
    }
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    int t ;
    scanf("%d",&t) ;
    while(t--)
    {
        int n , m ;
        scanf("%d%d",&n,&m) ;
        int a[n+1] , b[m+1] , ind[n+1] = {0} ;
        for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) , ind[a[i]] = i ;
        for(int i = 1 ; i <= m ; ++i) scanf("%d",&b[i]) ;
        int i = 1 ;
        long long ans = 0 ;
        while(i<m)
        {
            ans += (2*(ind[b[i]]-i)) + 1 ;
            int st = i ;
            ++i ;
            while(i<=m && ind[b[st]]>ind[b[i]])
            {
                ++ans ;
                ++i ;
            }
        }
        printf("%lld\n",ans) ;
    }
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    int t ;
    scanf("%d",&t) ;
    while(t--)
    {
        int n , m ;
        scanf("%d%d",&n,&m) ;
        int a[n+1] , b[m+1] , ind[n+1] = {0} ;
        for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) , ind[a[i]] = i ;
        for(int i = 1 ; i <= m ; ++i) scanf("%d",&b[i]) ;
        int i = 1 , ans = 0 ;
        while(i<m)
        {
            ans += (2*(ind[b[i]]-i)) + 1 ;
            ++i ;
            while(i<=m && ind[b[i-1]]>ind[b[i]])
            {
                ++ans ;
                ++i ;
            }
        }
        printf("%d\n",ans) ;
    }
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std ;

int main()
{
    int t ;
    scanf("%d",&t) ;
    while(t--)
    {
        int n , m ;
        scanf("%d%d",&n,&m) ;
        int a[n+1] , b[m+1] , ind[n+1] = {0} ;
        for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) , ind[a[i]] = i ;
        for(int i = 1 ; i <= m ; ++i) scanf("%d",&b[i]) ;
        int i = 1 ;
        long long ans = 0 ;
        while(i<m)
        {
            ans += max(1,((2*(ind[b[i]]-i)) + 1)) ;
            int st = i ;
            ++i ;
            while(i<=m && ind[b[st]]>ind[b[i]])
            {
                ++ans ;
                ++i ;
            }
        }
        printf("%lld\n",ans) ;
    }
    return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	int t; cin >> t;
	while (t--)
	{
		ll flag = 0, a, b, c;
		ll l, r, m; cin >> l >> r >> m;
		for (int i = l - r; i <= r - l; i++)
		{
			int j = l;
			if ((m - i) % j == 0)
			{
				a = j;
				if (i > 0)
				{
					b = i + l;
					c = l;
				}
				else
				{
					b = l;
					c =  l - i;
				}

				break;
			}

		}
		cout << a << " " << b << " " << c << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        for(int i=l;i<=r;i++){
                if(i>m){
                        int x=i-m;
                        if(x<=(r-l)){
                                cout<<i<<" "<<r-x<<" "<<r<<endl;
                                return;
                        }
                }
                else{
                        int x=m%i;
                        if(x<=(r-l)){
                                cout<<i<<" "<<r<<" "<<r-x<<endl;
                                return;
                        }
                }
        }
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>=m){
                cout<<l<<" "<<l<<" "<<l+(l-m);
        }
        else if((r-l)>=m-1){
                cout<<l<<" "<<r<<" "<<r-m%l;
        }
        else{
                int p=m%l,q=l;
                map<int,int>mp;
                for(int i=l;i<=r;i++){
                        int x=m%i;
                        if(mp[x]==1)break;
                        if(p>x){
                                p=x;
                                q=i;
                        }
                        mp[x]++;
                }
                cout<<q<<" "<<r<<" "<<r-p;
        }
        cout<<endl;
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>=m){
                cout<<l<<" "<<l<<" "<<l+(l-m);
                return;
        }
        int x=m%l,c=m/l;
        int a=0,b=(r-l),ans=0;
        while(a<b){
                int c1=(a+b)/2;
                if(c1*c<=x)a=c1+1,ans=c1;
                else b=c1;
        }
        x-=ans*c,l+=ans;
        cout<<l<<" "<<r<<" "<<r-x<<endl;
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>m){
                int x=l-m;
                        cout<<l<<" "<<r-x<<" "<<r<<endl;
                        return;
        }
        int ind=l,p=LLONG_MAX;
        for(int i=l;i<=r;i++){
                if(p>m%i){
                        p=m%i;
                        ind=i;
                }
        }
        cout<<ind<<" "<<r<<" "<<r-p<<endl;
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>=m){
                cout<<l<<" "<<l<<" "<<l+(l-m);
                return;
        }
        int x=m%l,c=m/l;
        while(l<=r && x>c){
                l++;
                x-=c;
        }
        cout<<l<<" "<<r<<" "<<r-x<<endl;
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>=m){
                cout<<l<<" "<<l<<" "<<l+(l-m);
                return;
        }
        int x=m%l,c=m/l;
        while(1){
                if(x>(r-l)){
                        l++;
                        x=m%l;
                }
                else{
                        cout<<l<<" "<<r<<" "<<r-x<<endl;
                        return;
                }
        }
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        int l1=l,r1=r,ans=0;
        while(l<r){
                int p=(l+r)/2;
                if(p>0 && m/p)ans=p,r=p;
                else l=p+1;
        }
        int x=0;
        if(ans==0)x=m;
        else x=m%ans;
        cout<<ans<<" "<<r<<" "<<r-x<<endl;

}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>=m){
                cout<<l<<" "<<l<<" "<<l+(l-m);
                return;
        }
        int x=m%l,c=m/l;
        int a=l,b=r,ans=0;
        while(a<b){
                int c1=(a+b)/2;
                if(c1*c<=x)a=c1+1,ans=c1;
                else b=c1;
        }
        x-=ans*c,l+=ans;
        cout<<l<<" "<<r<<" "<<r-x<<endl;
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>=m){
                cout<<l<<" "<<l<<" "<<l+(l-m);
                return;
        }
        int x=m%l,c=m/l;
        int a=0,b=(r-l)%l,ans=0;
        while(a<b){
                int c1=(a+b)/2;
                if(c1*c<=x)a=c1+1,ans=c1;
                else b=c1;
        }
        x-=ans*c,l+=ans;
        cout<<l<<" "<<r<<" "<<r-x<<endl;
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        for(int i=l;i<=l;i++){
                if(i>m){
                        int x=i-m;
                        if(x<=(r-l)){
                                cout<<i<<" "<<r-x<<" "<<r<<endl;
                                return;
                        }
                }
                else{
                        int x=m%i;
                        if(x<=(r-l)){
                                cout<<i<<" "<<r<<" "<<r-x<<endl;
                                return;
                        }
                }
        }
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        // if(l>=m){
        //         cout<<l<<" "<<l<<" "<<l+(l-m)<<endl;
        //         return;
        // }
        for(int i=l;i<=r;i++){
                int x=m%i,rem=0;
                if(x)rem=i-x;
                if(rem<=(r-l)){
                        cout<<i<<" "<<l<<" "<<l+rem<<endl;
                        return;
                }
                if(x<=(r-l)){
                        cout<<i<<" "<<r<<" "<<r-x<<endl;
                        return;
                }
        }
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include<bits/stdc++.h>
using namespace std;
#define dhiraj ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
#define pie 3.1415926536
#define onecount(n) __builtin_popcount(n)
#define leadingzeros(n) __builtin_clzll(n)
#define lb(v,x) lower_bound(v.begin(), v.end(), x)
#define ub(v,x) upper_bound(v.begin(), v.end(), x)
#define fo(i,n) for(i=0;i<n;i++)
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#warning Check Divide by zero
#warning Check Array size
#warning Check Base Case
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef vector<pair<int,int>>vii;
struct abc{int ind,z,y,x;};
bool compare(abc a1,abc a2){if(a1.x==a2.x)return a1.y>a2.y;return a1.x<a2.x;}
bool sortindex(abc a1,abc a2){return a1.y<a2.y;}
int countDivisors(int n){int cnt=0;for(int i=1;i<=sqrt(n);i++){if(n%i==0){if(n/i == i)cnt++;else cnt+=2;}}return cnt;}
bool isprime(int n){for(int i=2;i<=sqrt(n);i++)if(n%i==0)return false;return true;}
int lcm(int a,int b){return (a*b)/__gcd(a,b);}
const int mod=1e9+7;
int i,j,k,l,m,n,r,t,ans,res;
void solve(){
        cin>>l>>r>>m;
        if(l>=m){
                cout<<l<<" "<<l<<" "<<l+(l-m);
                return;
        }
        int x=m%l,c=m/l;
        while(x>(r-l)){
                x-=c;l++;
        }
        cout<<l<<" "<<r<<" "<<r-x<<endl;
}
int32_t main(){
        dhiraj
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);

        test
        solve();
}


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    string p = "abacaba";
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        ll a;
        for(int i=l;i<=r;i++){
            if(m%i==0){
                cout<<i<<" "<<r<<" "<<r<<endl;
                break;
            }
            else{
                if(m<=i){
                    ll diff = m-i;
                    cout<<i<<" "<<l<<" "<<l-diff<<endl;
                    break;
                }
                ll rem = m%i;
                if(rem<=(r-l)){
                    cout<<i<<" "<<(l+rem)<<" "<<l<<endl;
                    break;
                }
            }
        }

    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        ll rem = 10e10;
        int done = false;
        if(m<=l){
            ll diff = m-l;
            cout<<l<<" "<<(r+diff)<<" "<<(r)<<endl;
            done = true;
        }
        // else if(m<=r){
        //     done = true;
        //     cout<<m<<" "<<r<<" "<<r<<endl;
        // }
        else{
            if(!done){
                cout<<l<<" "<<l+(m%l)<<" "<<l<<endl;
            }
        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        for(int i=l;i<=r;i++){
            ll rem = m%i;
            ll diff = i-rem;
            if(m>=i){
                if(rem<=(r-l)){
                    cout<<i<<" "<<(l+rem)<<" "<<l<<endl;
                    break;
                }
            }
            if(diff<=(r-l)){
                cout<<i<<" "<<l<<" "<<(l+diff)<<endl;
                break;
            }

        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    string p = "abacaba";
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        ll rem = 500001;
        ll a;
        int done = false;
        if(m<=l){
            ll diff = m-l;
            cout<<l<<" "<<(r+diff)<<" "<<(r)<<endl;
            done = true;
        }
        for(int i=l;i<=r;i++){
            if(m%i==0){
                done = true;
                cout<<i<<" "<<l<<" "<<l<<endl;
            }
            else{
                if(m%i<rem){
                    rem = m%i;
                    a=i;
                }
            }
        }
        if(!done){
            ll b = l+rem;
            ll c = l;
            cout<<a<<" "<<b<<" "<<c<<endl;
        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        for(int i=l;i<=r;i++){
            ll rem = m%i;
            ll diff = i-m;
            if(m>=i){
                if(rem<=(r-l)){
                    cout<<i<<" "<<(l+rem)<<" "<<l<<endl;
                    break;
                }
            }
            if(diff<=(r-l)){
                cout<<i<<" "<<l<<" "<<(l+diff)<<endl;
                break;
            }

        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    string p = "abacaba";
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        for(int i=l;i<=r;i++){
            ll rem = m%i;
            ll diff = m-i;
            if(m<=i && abs(diff)<=(r-l)){
                cout<<i<<" "<<l<<" "<<l-diff<<endl;
                break;
            }
            if(m>=i&&rem<=(r-l)){
                cout<<i<<" "<<(l+rem)<<" "<<l<<endl;
                break;
            }
        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    string p = "abacaba";
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        ll rem = 10e10;
        int done = false;
        if(m<=l){
            ll diff = m-l;
            cout<<l<<" "<<(r+diff)<<" "<<(r)<<endl;
            done = true;
        }
        else if(m<=r){
            done = true;
            cout<<m<<" "<<l<<" "<<l<<endl;
        }
        else{
            ll a;
            for(int i=l;i<=r;i++){
                if(m%i==0){
                    done = true;
                    cout<<i<<" "<<l<<" "<<l<<endl;
                }
                else{
                    if((m%i)<rem){
                        rem = m%i;
                        a=i;
                    }
                }
            }
            if(!done){
                ll b = r-rem;
                ll c = r;
                cout<<a<<" "<<c<<" "<<b<<endl;
            }
        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    string p = "abacaba";
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        ll a;
        for(int i=l;i<=r;i++){
            if(m%i==0){
                cout<<i<<" "<<r<<" "<<r<<endl;
                break;
            }
            else{
                ll rem = m%i;
                ll diff = i-m;
                if(rem<(r-l)){
                    cout<<i<<" "<<(i+rem)<<" "<<i<<endl;
                    break;
                }
                else if(diff<=(r-l)){
                    cout<<i<<" "<<i<<" "<<i+diff<<endl;
                    break;
                }
            }
        }

    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    string p = "abacaba";
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        ll a;
        for(int i=l;i<=r;i++){
            if(m%i==0){
                cout<<i<<" "<<r<<" "<<r<<endl;
                break;
            }
            else{
                if(m<=i){
                    ll diff = m-i;
                    cout<<i<<" "<<(i)<<" "<<i-diff<<endl;
                    break;
                }
                ll rem = m%i;
                if(rem<(r-l)){
                    cout<<i<<" "<<(i+rem)<<" "<<i<<endl;
                    break;
                }
            }
        }

    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        for(int i=l;i<=r;i++){
            ll rem = m%i;
            ll diff = i-m;
            if(m>=i&&rem<=(r-l)){
                cout<<i<<" "<<(l+rem)<<" "<<l<<endl;
                break;
            }
            if(diff<=(r-l)){
                cout<<i<<" "<<l<<" "<<(l+diff)<<endl;
                break;
            }

        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include <bits/stdc++.h>
#include <cmath>
#define ll long long int
#define um unordered_map
using namespace std;

int main() {
    string p = "abacaba";
    int t;
    cin>>t;
    while(t--){
        ll l,r,m;
        cin>>l>>r>>m;
        ll rem = 10e10;
        int done = false;
        if(m<=l){
            ll diff = m-l;
            cout<<l<<" "<<(r+diff)<<" "<<(r)<<endl;
            done = true;
        }
        // else if(m<=r){
        //     done = true;
        //     cout<<m<<" "<<r<<" "<<r<<endl;
        // }
        else{
            ll a;
            for(int i=l;i<=r;i++){
                if(m%i==0){
                    done = true;
                    cout<<i<<" "<<r<<" "<<r<<endl;
                }
                else{
                    if((m%i)<rem){
                        rem = m%i;
                        a=i;
                    }
                }
            }
            if(!done){
                ll b = l+rem;
                ll c = l;
                cout<<a<<" "<<b<<" "<<c<<endl;
            }
        }
    }
    return 0;
}
auto x = [](){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();


#include<bits/stdc++.h>
using namespace std ;
# define pb push_back
# define ll long long
# define mp make_pair
# define endl "\n"

void solve() {
	ll l1,r,m ;
	cin >> l1 >> r >> m ;

	for(ll l = l1 ; l<=r ; ++l)  {
		ll dif = r- l1 ;
		ll req = m%l ;
		ll fac = m/l ;
		if(req <= dif && fac >= 1 ) {
			cout << l << " "  << l1 + req << " " << l1 << endl ;
			return ;
		} else if(fac >= 0  ){
			req = l - req ;
			if(req <= dif)
			cout << l << " " << l1 << " " << l1 + req << endl  ;
			return ;
		}
	}

}

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL) ;

   	int t ;
   	cin >> t;
   	while(t--)
   		solve() ;
   	return 0;
}


#include<bits/stdc++.h>
using namespace std ;
# define pb push_back
# define ll long long
# define mp make_pair
# define endl "\n"

void solve() {
	ll l,r,m ;
	cin >> l>> r >> m ;
	if(m >= l && m <= r ) {
		cout << m << " " << m << " " << m << endl ;
		return ;
	}
	ll dif = r - l  ;
	ll fac = m / l ;
	ll rem = m % l ;
	cout << l << " " ;
	if(fac >= 1 && rem <= dif) {
		cout << l + rem << " " << l << endl ;
	}
	else {
		cout << l << " " << l + l - rem << endl ;
	}

}

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL) ;

   	int t ;
   	cin >> t;
   	while(t--)
   		solve() ;
   	return 0;
}