# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.15.2
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# Question 1 Detect Floating Point Number

import re
for _ in range(int(input())):
    print(bool(re.match(r'^[-+]?[0-9]*\.[0-9]+$', input())))

# +
# Question 2 Re.split()

regex_pattern = r"[.,]+"	# Do not delete 'r'.

import re
print("\n".join(re.split(regex_pattern, input())))

# +
#Question 3 Group(), Groups() & Groupdict()

import re
m = re.search(r'([A-Za-z0-9])\1+',input())
if m:
    print(m.group(1))
else:
    print(-1)

# +
# Question 4 Re.findall() & Re.finditer()

import re

k = re.findall(r'(?<=[^aeiouAEIOU ])[aeiouAEIOU]{2,}(?=[^aeiouAEIOU ])',input())

if k:
    for i in k:
        print(i)
else:
    print(-1)

# +
# Question 5 Re.start() & Re.end()

import re

S, k = input(), input()
matches = re.finditer(r'(?=(' + k + '))', S)

anymatch = False
for match in matches:
    anymatch = True
    print((match.start(1), match.end(1) - 1))

if anymatch == False:
    print((-1, -1))

# +
# Question 6 Regex Substitution

import re
T = []
def change(match):
    if match.group(0) == '&&':
        return 'and'
    elif  match.group(0) == '||':
        return 'or'
    
    
N = int(input())
for i in range(N):
    T.append(input())
    
t = '\n'.join(T)

print(re.sub(r"(?<= )(&&|\|\|)(?= )", change, t))

# +
#Question 7 Validating Roman Numerals

regex_pattern = r"^(?=[MDCLXVI])M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"	# Do not delete 'r'.

import re
print(str(bool(re.match(regex_pattern, input()))))

# +
#Question 8 Validating phone numbers

import re

N = int(input())

for i in range(N):
    number = input()
    if(len(number)==10 and number.isdigit()):
        output = re.findall(r"^[789]\d{9}$",number)
        if(len(output)==1):
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

# +
# Question 9 Validating and Parsing Email Addresses

import re

N = int(input())

for i in range(N):
    name, email = input().split()
    pattern="<[a-z][a-zA-Z0-9\-\.\_]+@[a-zA-Z]+\.[a-zA-Z]{1,3}>"
    if bool(re.match(pattern, email)):
        print(name,email)

# +
# Question 10 Hex Color Code


import re

n = int(input().strip())
inside = False
for _ in range(n):
    line = input()
    
    for el in line.split(' '):
        if el == "{":
            inside = True
            continue
        elif el == "}":
            inside = False
            continue
        elif inside:
            found = re.search(r'\#[0-9a-fA-F]{3,6}', el)
            if found:
                print(found.group(0))

# +
# Question 11 HTML Parser - Part 1

from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
    def handle_starttag(self, tag, attrs):
        print ('Start :',tag)
        for attr in attrs:
                print ('->',' > '.join(map(str,attr)))
    def handle_endtag(self, tag):
        print ('End   :',tag)
    def handle_startendtag(self, tag, attrs):
        print ('Empty :',tag)
        for attr in attrs:
                print ('->',' > '.join(map(str,attr)))

html = ""
for i in range(int(input())):
    html += input()
                    
                
parser = MyHTMLParser()
parser.feed(html)
parser.close()

# +
# Question 12 HTML Parser - Part 2

from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
    def handle_comment(self, data):
        if '\n' not in data:
            print('>>> Single-line Comment')
            print(data)
        elif '\n' in data:
            print('>>> Multi-line Comment')
            print(data)
    def handle_data(self, data):
        if data != '\n':
            print('>>> Data')
            print(data)
  
html = ""       
for i in range(int(input())):
    html += input().rstrip()
    html += '\n'
    
parser = MyHTMLParser()
parser.feed(html)
parser.close()

# +
# Question 13 Detect HTML Tags, Attributes and Attribute Values

from __future__ import print_function
import sys
if sys.version_info[0]>=3:
	input=input
	from html.parser import HTMLParser

from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
	def handle_starttag(self, tag, attrs):
		print(tag)
		for e in attrs: print("-> "+e[0]+" > "+str(e[1]))
	def handle_endtag(self, tag):
		#print("End   : "+tag)
		pass
	def handle_startendtag(self, tag, attrs):
		print(tag)
		for e in attrs: print("-> "+e[0]+" > "+str(e[1]))

parser = MyHTMLParser()
for _ in range(int(input())):
	parser.feed(input())

# +
# Question 14 Validating UID

import re
for i in range(int(input())):
    N = input().strip()
    if N.isalnum() and len(N) == 10:
        if bool(re.search(r'(.*[A-Z]){2,}',N)) and bool(re.search(r'(.*[0-9]){3,}',N)):
            if re.search(r'.*(.).*\1+.*',N):
                print ('Invalid')
            else:
                print ('Valid')  
        else:
            print ('Invalid')
    else:
        print ('Invalid')

# +
# Question 15 Validating Credit Card Numbers

import re
for i in range(int(input())):
    S = input().strip()
    pre_match = re.search(r'^[456]\d{3}(-?)\d{4}\1\d{4}\1\d{4}$',S)
    if pre_match:
        processed_string = "".join(pre_match.group(0).split('-'))
        final_match = re.search(r'(\d)\1{3,}',processed_string)
        if final_match:
            print('Invalid')
        else :
            print('Valid')
    else:
        print('Invalid')

# +
# Question 16 Validating Postal Codes

regex_integer_in_range = r"^[1-9]\d{5}$"	# Do not delete 'r'.
regex_alternating_repetitive_digit_pair = r"(\d)(?=\d\1)"	# Do not delete 'r'.


import re
P = input()

print (bool(re.match(regex_integer_in_range, P)) 
and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)

# +
# Question 17 Matrix Script

import math
import os
import random
import re
import sys

first_multiple_input = input().rstrip().split()

n = int(first_multiple_input[0])

m = int(first_multiple_input[1])

matrix = []

for _ in range(n):
    matrix_item = input()
    matrix.append(matrix_item)
      
matrix = list(zip(*matrix))

sample = str()

for words in matrix:
    for char in words:
        sample += char
       
print(re.sub(r'(?<=\w)([^\w\d]+)(?=\w)', ' ', sample))

# -


