1 #include
2 #include<string.h>
3 #include
4 #include
5 using namespace std;
6 int d1[2000000],n;
7 struct node
8 {
9 int g,h;
10 } t[2000000];
11 int cmp(struct node a,struct node b)
12 {
13 if(a.h==b.h)
14 return a.g<b.g;
15 return a.h<b.h;
16 }
17 int lowbit(int x)
18 {
19 return x&(-x);
20 }
21 long long sum(int x)
22 {
23 long long res=0;
24 while(x>0)
25 {
26 res+=d1[x];
27 x-=lowbit(x);
28 }
29 return res;
30 }
31 void add(int x)
32 {
33 while(x<=20000)
34 {
35 d1[x]++;
36 x+=lowbit(x);
37 }
38 }
39 int main()
40 {
41 int a,c,b,i,j,k=0;
42 scanf("%d",&a);
43 while(a--)
44 {
45 memset(d1,0,sizeof(d1));
46 scanf("%d%d%d",&n,&b,&c);
47 for(i=0; i)
48 {
49 scanf("%d%d",&t[i].g,&t[i].h);
50 }
51 sort(t,t+c,cmp);
52 long long ans=0;
53 for(i=0; i)
54 {
55 ans+=sum(b)-sum(t[i].g);
56 add(t[i].g);
57 }
58 printf("Test case %d: %lld\n",++k,ans);
59 }
60 }