class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

g = A("g")
h = B("h")
l = A("l")
b = B("b")
c = B("c")
e = A("e")
m = A("m")
k = A("k")
d = B("d")

g.q = c
h.t = l
l.q = b
b.t = m
c.t = k
e.q = h
m.q = d
k.q = d
d.t = g
assert e.q.t.q.t.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

g = A("g")
h = B("h")
l = A("l")
b = B("b")
c = B("c")
e = A("e")
m = A("m")
k = A("k")
d = B("d")

g.q = c
h.t = l
l.q = b
b.t = m
c.t = k
e.q = h
m.q = d
k.q = d
d.t = g
assert e.q.t.q.t.q.t.q.txt == "c"