#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	int a, b, i, j, weigh[35], limt[35], count;
	cin>>a;
	while(a--) {
		cin>>b;
		count=0;
		for(i=0; i<b; i++) cin>>weigh[i];
		for(j=0; j<b; j++) cin>>limt[j];
		std::stable_sort(weigh, weigh+b);
		std::stable_sort(limt, limt+b);
		for(i=0, j=0; i<b && j<b; i++) {
		while(j<b && weigh[i]>limt[j]) {
			j++;
		}
		if(j<b) {
			count++; j++;
		}
		}
		cout<<count<<endl;
	}
	return 0;
}