#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int binarySearch(int *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ quickSort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int i, j, k, c, len, num, temp, t, x, y, min, m, n;
  int arr[100001];
  int copy[100001];
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &num);
    for (i = 0; i < num; i++) {
      scanf("%d", &m);
      scanf("%d %d", &x, &y);
      min = x;
      for (j = 1; j < m; j++) {
        scanf("%d %d", &x, &y);
        min = ((x) < (min) ? (x) : (min));
      }
      copy[i] = arr[i] = min;
    }
    quickSort(copy, 0, num - 1);
    for (i = 0; i < num; i++) {
      printf("%d ", num - 1 - binarySearch(copy, arr[i], num));
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc3560,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
je     12d9 <main+0x199>
lea    0xe84(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1255 <main+0x115>
lea    0xe5f(%rip),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe4a(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    122e <main+0xee>
lea    0xe1b(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    120e <main+0xce>
mov    -0x28(%rbp),%eax
mov    %eax,-0xc3554(%rbp)
jmp    1217 <main+0xd7>
mov    -0x30(%rbp),%eax
mov    %eax,-0xc3554(%rbp)
mov    -0xc3554(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d2 <main+0x92>
mov    -0x30(%rbp),%ecx
movslq -0x8(%rbp),%rax
mov    %ecx,-0x61ac0(%rbp,%rax,4)
movslq -0x8(%rbp),%rax
mov    %ecx,-0xc3550(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1191 <main+0x51>
lea    -0xc3550(%rbp),%rdi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1060 <quickSort@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12c6 <main+0x186>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc3558(%rbp)
lea    -0xc3550(%rbp),%rdi
movslq -0x8(%rbp),%rax
mov    -0x61ac0(%rbp,%rax,4),%esi
mov    -0x1c(%rbp),%edx
call   1040 <binarySearch@plt>
mov    -0xc3558(%rbp),%esi
sub    %eax,%esi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1270 <main+0x130>
lea    0xd3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1164 <main+0x24>
xor    %eax,%eax
add    $0xc3560,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc3538,%rsp
lea    0xe9b(%rip),%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0x18(%rsp)
jae    118f <main+0x3f>
xor    %eax,%eax
add    $0xc3538,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6a(%rip),%r13
lea    0x14(%rsp),%r12
lea    0x1c(%rsp),%r14
lea    0x20(%rsp),%rbp
lea    0xe5a(%rip),%rbx
jmp    11c9 <main+0x79>
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0x18(%rsp)
mov    %rbp,%rbx
lea    0x20(%rsp),%rbp
jb     117b <main+0x2b>
lea    0xe33(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
jle    1285 <main+0x135>
xor    %r15d,%r15d
jmp    1212 <main+0xc2>
nopl   (%rax)
mov    %ebp,0x61ab0(%rsp,%r15,4)
mov    %ebp,0x20(%rsp,%r15,4)
add    $0x1,%r15
movslq 0xc(%rsp),%rdx
cmp    %rdx,%r15
lea    0xdf6(%rip),%rbx
jge    1280 <main+0x130>
lea    0xdea(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x14(%rsp),%ebp
cmpl   $0x2,0x10(%rsp)
jl     11f0 <main+0xa0>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    %ebp,%eax
cmovl  %eax,%ebp
add    $0x1,%ebx
cmp    0x10(%rsp),%ebx
jl     1250 <main+0x100>
jmp    11f0 <main+0xa0>
nopw   0x0(%rax,%rax,1)
lea    0x20(%rsp),%rbp
add    $0xffffffff,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1070 <quickSort@plt>
mov    0xc(%rsp),%r15d
test   %r15d,%r15d
mov    %rbx,%rbp
jle    11b0 <main+0x60>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x61ab0(%rsp,%rbx,4),%esi
lea    0x20(%rsp),%rdi
mov    %r15d,%edx
call   1050 <binarySearch@plt>
not    %eax
add    %eax,%r15d
mov    %rbp,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%r15
cmp    %r15,%rbx
jl     12b0 <main+0x160>
jmp    11b0 <main+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [4 x i8] c"%d \00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [100001 x i32]
%16 = alloca [100001 x i32]
store i32 0, i32* %1
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
br label %18
18: ; preds = %85, %0
%19 = load i32, i32* %9
%20 = add nsw i32 %19, -1
store i32 %20, i32* %9
%21 = icmp ne i32 %19, 0
br i1 %21, label %22, label %87
22: ; preds = %18
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 0, i32* %2
br label %24
24: ; preds = %58, %22
%25 = load i32, i32* %2
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %61
28: ; preds = %24
%29 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%30 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %10, i32* %11)
%31 = load i32, i32* %10
store i32 %31, i32* %12
store i32 1, i32* %3
br label %32
32: ; preds = %47, %28
%33 = load i32, i32* %3
%34 = load i32, i32* %13
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %50
36: ; preds = %32
%37 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %10, i32* %11)
%38 = load i32, i32* %10
%39 = load i32, i32* %12
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = load i32, i32* %10
br label %45
43: ; preds = %36
%44 = load i32, i32* %12
br label %45
45: ; preds = %43, %41
%46 = phi i32 [ %42, %41 ], [ %44, %43 ]
store i32 %46, i32* %12
br label %47
47: ; preds = %45
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %32
50: ; preds = %32
%51 = load i32, i32* %12
%52 = load i32, i32* %2
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [100001 x i32], [100001 x i32]* %15, i64 0, i64 %53
store i32 %51, i32* %54
%55 = load i32, i32* %2
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [100001 x i32], [100001 x i32]* %16, i64 0, i64 %56
store i32 %51, i32* %57
br label %58
58: ; preds = %50
%59 = load i32, i32* %2
%60 = add nsw i32 %59, 1
store i32 %60, i32* %2
br label %24
61: ; preds = %24
%62 = getelementptr inbounds [100001 x i32], [100001 x i32]* %16, i64 0, i64 0
%63 = load i32, i32* %7
%64 = sub nsw i32 %63, 1
%65 = call i32 @quickSort(i32* %62, i32 0, i32 %64)
store i32 0, i32* %2
br label %66
66: ; preds = %82, %61
%67 = load i32, i32* %2
%68 = load i32, i32* %7
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %85
70: ; preds = %66
%71 = load i32, i32* %7
%72 = sub nsw i32 %71, 1
%73 = getelementptr inbounds [100001 x i32], [100001 x i32]* %16, i64 0, i64 0
%74 = load i32, i32* %2
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [100001 x i32], [100001 x i32]* %15, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = load i32, i32* %7
%79 = call i32 @binarySearch(i32* %73, i32 %77, i32 %78)
%80 = sub nsw i32 %72, %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %70
%83 = load i32, i32* %2
%84 = add nsw i32 %83, 1
store i32 %84, i32* %2
br label %66
85: ; preds = %66
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %18
87: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100001 x i32]
%7 = alloca [100001 x i32]
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
%13 = bitcast [100001 x i32]* %6 to i8*
%14 = bitcast [100001 x i32]* %7 to i8*
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
%18 = icmp eq i32 %16, 0
br i1 %18, label %74, label %19
19: ; preds = %0
%20 = getelementptr inbounds [100001 x i32], [100001 x i32]* %7, i64 0, i64 0
br label %21
21: ; preds = %19, %69
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%23 = load i32, i32* %1
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %21, %42
%26 = phi i64 [ %46, %42 ], [ 0, %21 ]
%27 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%28 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%29 = load i32, i32* %3
%30 = load i32, i32* %5
%31 = icmp sgt i32 %30, 1
br i1 %31, label %32, label %42
32: ; preds = %25, %32
%33 = phi i32 [ %38, %32 ], [ %29, %25 ]
%34 = phi i32 [ %39, %32 ], [ 1, %25 ]
%35 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%36 = load i32, i32* %3
%37 = icmp slt i32 %36, %33
%38 = select i1 %37, i32 %36, i32 %33
%39 = add nuw nsw i32 %34, 1
%40 = load i32, i32* %5
%41 = icmp slt i32 %39, %40
br i1 %41, label %32, label %42
42: ; preds = %32, %25
%43 = phi i32 [ %29, %25 ], [ %38, %32 ]
%44 = getelementptr inbounds [100001 x i32], [100001 x i32]* %6, i64 0, i64 %26
store i32 %43, i32* %44
%45 = getelementptr inbounds [100001 x i32], [100001 x i32]* %7, i64 0, i64 %26
store i32 %43, i32* %45
%46 = add nuw nsw i64 %26, 1
%47 = load i32, i32* %1
%48 = sext i32 %47 to i64
%49 = icmp slt i64 %46, %48
br i1 %49, label %25, label %50
50: ; preds = %42, %21
%51 = phi i32 [ %23, %21 ], [ %47, %42 ]
%52 = add nsw i32 %51, -1
%53 = call i32 @quickSort(i32* %20, i32 0, i32 %52)
%54 = load i32, i32* %1
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %69
56: ; preds = %50, %56
%57 = phi i64 [ %65, %56 ], [ 0, %50 ]
%58 = phi i32 [ %66, %56 ], [ %54, %50 ]
%59 = getelementptr inbounds [100001 x i32], [100001 x i32]* %6, i64 0, i64 %57
%60 = load i32, i32* %59
%61 = call i32 @binarySearch(i32* %20, i32 %60, i32 %58)
%62 = xor i32 %61, -1
%63 = add i32 %58, %62
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %63)
%65 = add nuw nsw i64 %57, 1
%66 = load i32, i32* %1
%67 = sext i32 %66 to i64
%68 = icmp slt i64 %65, %67
br i1 %68, label %56, label %69
69: ; preds = %56, %50
%70 = call i32 @putchar(i32 10)
%71 = load i32, i32* %2
%72 = add nsw i32 %71, -1
store i32 %72, i32* %2
%73 = icmp eq i32 %71, 0
br i1 %73, label %74, label %21
74: ; preds = %69, %0
ret i32 0
}