This problem admits some very short solutions, based on regular expressions:
Sergiu Pușcaș - Python 3
1 #!/usr/bin/python3 2 import re 3 4 for _ in range(int(input())): 5 s = input() 6 print("Correct!" if re.match("[A-Z]{2}\s[0-9]{2}\s[A-Z]{3}", s) or \ 7 re.match("B\s[0-9]{2,3}\s[A-Z]{3}", s) else "Incorrect!")
Petru Trîmbițaș - Perl
1 use v5.16; 2 use warnings; 3 4 my $n = <>; 5 chomp $n; 6 for (1..$n) { 7 my $line = <>; 8 chomp $line; 9 if($line =~ /^(([A-Z][A-Z]\ [0-9]{2})|(B\ [0-9]{2,3}))\ [A-Z]{3}$/) { 10 say "Correct!"; 11 } else { 12 say "Incorrect!"; 13 } 14 }
Marius Gavrilescu - Perl
1 #!/usr/bin/perl 2 use v5.14; 3 use warnings; 4 <>; 5 say /^([A-Z][A-Z] \d\d|B \d{2,3}) [A-Z]{3}$/ ? 'Correct!' : 'Incorrect!' while <>;