title: The Grid Search (HackerRank) - Python
body: <p>I'm a developer for a few years but I'm practicing my algorithm skills.</p>
  
  <p>I'm faced with <a href="https://www.hackerrank.com/challenges/the-grid-search" rel="nofollow">"The Grid Search"</a> in HackerRank and even though I could solve it, I want to know if this is a decent method to do it.</p>
  
  <p>PS: I'm trying to to do most of it with simple instructions, developing the whole logic instead of using pre-built functions. My objective is to improve my logical thought, not my knowledge of a language's magic methods.</p>
  
  <pre><code>#!/bin/python3
  
  import sys
  
  
  t = int(input().strip())
  for a0 in range(t):
      R,C = input().strip().split(' ')
      R,C = [int(R),int(C)]
      G = []
      G_i = 0
      for G_i in range(R):
         G_t = list(input().strip())
         G.append(G_t)
      r,c = input().strip().split(' ')
      r,c = [int(r),int(c)]
      P = []
      P_i = 0
      for P_i in range(r):
         P_t = list(input().strip())
         P.append(P_t)
  
      mIsEqual = False
  
      #For each line of the matrix
      for a1 in range(0,len(G) - (len(P)-1)):
          #For each column of the given line
          for a2 in range(0,len(G[a1]) - (len(P[0])-1)):
              #If the top left value of the pattern matches the current value of the matrix, try to match it
              if(P[0][0] == G[a1][a2]):
                  #If the pattern 'fits' horizontally in the matrix, try to match it
                  if(len(P[0]) &lt;= (len(G[a1]) - a2)):
                      #If the pattern 'fits' vertically in the matrix, try to match it
                      if(len(P) &lt;= (len(G) - a1)):
                          #Match every single field of the pattern to the given area of the matrix.
                          for a3 in range(0,len(P)):
                              for a4 in range(0,len(P[0])):
                                  #If the fields are equal mIsEqual is true
                                  if(P[a3][a4] == G[a3+a1][a4+a2]):
                                      mIsEqual = True
                                  else:
                                  #If the fields are not equal stop matching this area of the matrix.
                                      mIsEqual = False
                                      break
                              #If one field in a line was not equal, stop matching this area of the matrix.
                              if(mIsEqual == False):
                                  break
                      #If, after matching the whole area with the pattern mIsEqual is still true, the pattern is there.
                      if(mIsEqual):
                          break
          #If the pattern was found in the previous line, no need to keep this going.
          if(mIsEqual):
              break
  
      if(mIsEqual == True):
          print("YES")
      else:
          print("NO")
  </code></pre>
  
  <p>I'm looking for any suggestions to improve this script or, if you think it's completely wrong, the reason why this is not a good way to do it.</p>
  
  <p>Thanks!</p>