## Validating Credit Card Numbers Solution

You and Fredrick are good friends. Yesterday, Fredrick received Â credit cards from ** ABCD Bank**. He wants to verify whether his credit card numbers are valid or not. You happen to be great at regex so he is asking for your help!

A valid credit card from ** ABCD Bank** has the following characteristics:

âș It must start with a , Â or .

âș It must contain exactly Â digits.

âș It must only consist of digits (-).

âș It may have digits in groups of , separated by

*hyphen*

*one***.**

**"-"**âș It must

**use any other separator like ' ' , '_', etc.**

`NOT`

âș It must

**have Â or more consecutive repeated digits.**

`NOT`

** Examples**:

_{Valid Credit Card Numbers}

```
4253625879615786
4424424424442444
5122-2368-7954-3214
```

_{Invalid Credit Card Numbers}

```
42536258796157867 #17 digits in card number â Invalid
4424444424442444 #Consecutive digits are repeating 4 or more times â Invalid
5122-2368-7954 - 3214 #Separators other than '-' are used â Invalid
44244x4424442444 #Contains non digit characters â Invalid
0525362587961578 #Doesn't start with 4, 5 or 6 â Invalid
```

**Input Format**

The first line of input contains an integer .

The next Â lines contain credit card numbers.

**Constraints**

**Output Format**

Print 'Valid' if the credit card number is valid. Otherwise, print 'Invalid'. Do not print the quotes.

**Sample Input**

```
6
4123456789123456
5123-4567-8912-3456
61234-567-8912-3456
4123356789123456
5133-3367-8912-3456
5123 - 3567 - 8912 - 3456
```

**Sample Output**

```
Valid
Valid
Invalid
Valid
Invalid
Invalid
```

**Explanation**

4123456789123456 : **Valid**

5123-4567-8912-3456 : **Valid**

61234--8912-3456 : ** Invalid**, because the card number is not divided into equal groups of .

4123356789123456 :

**Valid**51-67-8912-3456 :

**, consecutive digits Â is repeating Â times.**

**Invalid**5123456789123456 :

**, because space ' Â ' and**

**Invalid**`-`

are used as separators.### Solution in Python

```
import re
def check(card):
if not re.search("^[456]\d{3}(-?\d{4}){3}$",card) or re.search(r"(\d)\1{3}", re.sub("-", "",card)):
return False
return True
for i in range(int(input())):
print("Valid" if check(input()) else "Invalid")
```