title: check if a string A an anagram of a substring of another string B
body: <p>Rotate a given string(A) in specified direction by specified magnitude. After each rotation, make a note of first character of the rotated string. Once all the rotations are performed, the accumulated first characters of all rotated strings, constitute another string(B). Check if B is an anagram of any substring of A.
  Note: Every rotation is to be performed on the original string A.</p>
  <p><strong>Input format:</strong>
  First line of input contains T - number of test cases. First line of each test case contains A - original string. Second line of each test case contains Q - denoting number of queries (rotations). Each of the next Q lines contains 2 values D, M seperated by space, where D denotes direction of rotation and M denotes magnitude of rotation.</p>
  <p>constraints:</p>
  <pre><code>1 &lt;= size(A) &lt;= 10^5 
  0 &lt;= M &lt;= 10^5
  1 &lt;= T &lt;= 100
  'a' &lt;= A[i] &lt;= 'z'
  1 &lt;= Q &lt;= size(A).
  </code></pre>
  <p><em>I keep getting key error for line 35. I tried to trace it out but it's not working. Any help is appreciated.</em></p>
  <pre><code>def create(s):
      d={}
      for x in s:
          if x in d:
              d[x]+=1
          else:
              d[x]=1
      return d
  def check(a, b):
      for x in a:
          if x not in b or a[x]!=b[x]:
              return False
      return True
  def find(s, res):
      m = len(s)
      n = len(res)
      if n&gt;m:# if len(res)&gt;len(s) return False
          return False
      dres = create(res)#dict for the res string
      ds={}# dict for the original string, sliding window to be performed on this dict
      for i in range(n):
          if s[i] in ds:
              ds[s[i]]+=1
          else:
              ds[s[i]]=1
      if check(dres, ds):#check if the dictionaries are same
          return True
      for i in range(n, m):
          #updating the dict for the original string for the incoming character
          if s[i] in ds:
              ds[s[i]]+=1
          else:
              ds[s[i]]=1
          #updating the dict for the original string for the outgoing character
          ds[s[i-n]]-=1
          if ds[s[i-n]]==0:
              ds.pop(ds[s[i-n]])
          if check(dres, ds):
              return True
      return False
          
  for _ in range(int(input())):
      s = input()
      l=len(s)
      n=int(input())
      res=''
      while(n&gt;0):
          temp = list(input().split())
          if temp[0]==&quot;L&quot;:
              res+=s[int(temp[1])]
          elif temp[0]==&quot;R&quot;:
              res+=s[l - int(temp[1])]
          n-=1
      if find(s, res):
          print(&quot;Yes&quot;)
      else:
          print(&quot;No&quot;)
  </code></pre>
  <p><strong>INPUT:</strong></p>
  <pre><code>2
  abcdef
  3
  L 1
  L 5
  R 3
  markram
  3
  L 2
  R 2
  L 3
  </code></pre>
  <p><strong>OUTPUT:</strong></p>
  <pre><code>No
  Yes
  </code></pre>