#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 /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int T, n, i, obeyed;
  scanf("%d", &T);
  while (T--) {
    char str[501];
    obeyed = 1;
    scanf("%d", &n);
    scanf("%s", str);
    for (i = 0; i < n; i++) {
      if (!(str[i] == '.')) {
        if (str[i] == 'H') {
          if (obeyed == 0)
            break;
          else
            obeyed = 0;
        } else {
          if (obeyed == 1) {
            obeyed = 0;
            break;
          } else
            obeyed = 1;
        }
      }
    }
    (obeyed) ? printf("Valid\n") : printf("Invalid\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1244 <main+0x124>
movl   $0x1,-0x14(%rbp)
lea    0xe9a(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    -0x210(%rbp),%rsi
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1218 <main+0xf8>
movslq -0x10(%rbp),%rax
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0x2e,%eax
je     1205 <main+0xe5>
movslq -0x10(%rbp),%rax
movsbl -0x210(%rbp,%rax,1),%eax
ff
cmp    $0x48,%eax
jne    11de <main+0xbe>
cmpl   $0x0,-0x14(%rbp)
jne    11d2 <main+0xb2>
jmp    1218 <main+0xf8>
movl   $0x0,-0x14(%rbp)
jmp    1200 <main+0xe0>
cmpl   $0x1,-0x14(%rbp)
jne    11f4 <main+0xd4>
movl   $0x0,-0x14(%rbp)
jmp    1218 <main+0xf8>
movl   $0x1,-0x14(%rbp)
jmp    1200 <main+0xe0>
jmp    1205 <main+0xe5>
jmp    120a <main+0xea>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118d <main+0x6d>
cmpl   $0x0,-0x14(%rbp)
je     1233 <main+0x113>
lea    0xddd(%rip),%rdi
call   1030 <printf@plt>
jmp    123f <main+0x11f>
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
jmp    1144 <main+0x24>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
lea    0xec8(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    115f <main+0x3f>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9a(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xe91(%rip),%r12
lea    0x10(%rsp),%r13
lea    0xe90(%rip),%rbp
jmp    1193 <main+0x73>
lea    0xe7f(%rip),%rdi
call   1030 <puts@plt>
subl   $0x1,0x8(%rsp)
jb     114b <main+0x2b>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
mov    %rbp,%rdi
test   %eax,%eax
jle    1187 <main+0x67>
mov    $0x1,%ecx
xor    %edx,%edx
jmp    11e3 <main+0xc3>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x1,%ecx
mov    $0x1,%ecx
je     1180 <main+0x60>
add    $0x1,%rdx
cmp    %rdx,%rax
je     1200 <main+0xe0>
movzbl 0x10(%rsp,%rdx,1),%ebx
cmp    $0x2e,%bl
je     11da <main+0xba>
cmp    $0x48,%bl
jne    11d0 <main+0xb0>
test   %ecx,%ecx
mov    $0x0,%ecx
jne    11da <main+0xba>
jmp    1180 <main+0x60>
nopl   (%rax)
mov    %rbp,%rdi
test   %ecx,%ecx
jne    1187 <main+0x67>
jmp    1180 <main+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [7 x i8] c"Valid\0A\00"
@.str.3 = [9 x i8] c"Invalid\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [501 x i8]
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %8
8: ; preds = %58, %0
%9 = load i32, i32* %2
%10 = add nsw i32 %9, -1
store i32 %10, i32* %2
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %60
12: ; preds = %8
store i32 1, i32* %5
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = getelementptr inbounds [501 x i8], [501 x i8]* %6, i64 0, i64 0
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %4
br label %16
16: ; preds = %48, %12
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %51
20: ; preds = %16
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [501 x i8], [501 x i8]* %6, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 46
br i1 %26, label %47, label %27
27: ; preds = %20
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [501 x i8], [501 x i8]* %6, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 72
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
br label %51
38: ; preds = %34
store i32 0, i32* %5
br label %39
39: ; preds = %38
br label %46
40: ; preds = %27
%41 = load i32, i32* %5
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %44
43: ; preds = %40
store i32 0, i32* %5
br label %51
44: ; preds = %40
store i32 1, i32* %5
br label %45
45: ; preds = %44
br label %46
46: ; preds = %45, %39
br label %47
47: ; preds = %46, %20
br label %48
48: ; preds = %47
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %16
51: ; preds = %43, %37, %16
%52 = load i32, i32* %5
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %51
%55 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %58
56: ; preds = %51
%57 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %58
58: ; preds = %56, %54
%59 = phi i32 [ %55, %54 ], [ %57, %56 ]
br label %8
60: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@str = [8 x i8] c"Invalid\00"
@str.4 = [6 x i8] c"Valid\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [501 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = add nsw i32 %7, -1
store i32 %8, i32* %1
%9 = icmp eq i32 %7, 0
br i1 %9, label %41, label %10
10: ; preds = %0
%11 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 0
br label %12
12: ; preds = %10, %35
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %12
%18 = zext i32 %15 to i64
br label %19
19: ; preds = %17, %28
%20 = phi i64 [ 0, %17 ], [ %30, %28 ]
%21 = phi i32 [ 1, %17 ], [ %29, %28 ]
%22 = getelementptr inbounds [501 x i8], [501 x i8]* %3, i64 0, i64 %20
%23 = load i8, i8* %22
switch i8 %23, label %26 [
i8 46, label %28
i8 72, label %24
]
24: ; preds = %19
%25 = icmp eq i32 %21, 0
br i1 %25, label %34, label %28
26: ; preds = %19
%27 = icmp eq i32 %21, 1
br i1 %27, label %34, label %28
28: ; preds = %26, %24, %19
%29 = phi i32 [ %21, %19 ], [ 0, %24 ], [ 1, %26 ]
%30 = add nuw nsw i64 %20, 1
%31 = icmp eq i64 %30, %18
br i1 %31, label %32, label %19
32: ; preds = %28
%33 = icmp eq i32 %29, 0
br i1 %33, label %34, label %35
34: ; preds = %26, %24, %32
br label %35
35: ; preds = %32, %12, %34
%36 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0), %34 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.4, i64 0, i64 0), %12 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.4, i64 0, i64 0), %32 ]
%37 = call i32 @puts(i8* dereferenceable(1) %36)
%38 = load i32, i32* %1
%39 = add nsw i32 %38, -1
store i32 %39, i32* %1
%40 = icmp eq i32 %38, 0
br i1 %40, label %41, label %12
41: ; preds = %35, %0
ret i32 0
}