The code above is just the definition of a function. If you submit it, the function will never be called, no output generated, resulting in TLE.
You have to add some code to process the input and to call your function with correct parameters.
E.g.
def main():
number_of_cases = int(input())
for dummy in range(number_of_cases):
data = input().split()
lines, columns = map(int, data)
charpat(lines, columns)
print()
if __name__ == "__main__":
main()
With this you can get accepted, although the algorithm can be optimized, as Leppy explained.