//poj1083 想了很多,尤其是贪心算法,结果很多情况,一直想用递归贪心解决。最后失败。
//失败的数据集: 10 100, 50 120, 130 200, 110 135, 121 124,结果是20
//最后采用小优的方法 全部放到同一栏中,只要输出最大重复的走廊次数就可以。
#include <iostream>
#include <algorithm>
using namespace std;
int s[205], t[205];
int room[401];
int main()
{
int n;
cin>>n;
while(n--)
{
memset(s, 0, sizeof(s));
memset(t, 0, sizeof(t));
memset(room, 0, sizeof(room));
int f;
cin>>f;
for(int i = 0; i < f; i++)
{
cin>>s[i]>>t[i];
if(s[i] > t[i])
{
int temp = s[i];
s[i] = t[i];
t[i] = temp;
}
if(s[i] % 2 != 0)
s[i]++;
if(t[i] % 2 != 0)
t[i]++;
for(int j = s[i]; j <= t[i]; j++)
{
room[j]++;
}
}
sort(room, room + 401);
cout<<room[400] * 10 <<endl;
}
return 0;
}