How can I optimize my strq code?

o=raw_input()
n=int(raw_input())
for i in xrange(0,n):
a,b,c,d=raw_input().split()
c=int©-1
d=int(d)
ans=0
for i in xrange(c,d):
if(o[i]==a):
ans+=o[i+1:d].count(b)
print(ans)

It gives TLE in many cases?How can I reduce the tle in this sum? or should I try entirely different approach? Link of Question:https://www.codechef.com/problems/STRQ