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

class B:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

l = A("l")
a = B("a")
f = C("f")
j = C("j")
g = B("g")
e = B("e")
h = C("h")
c = C("c")

l.w = g
a.s = h
f.q = g
j.q = g
g.s = h
e.s = h
h.q = a
c.q = e
assert e.s.q.s.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

l = A("l")
a = B("a")
f = C("f")
j = C("j")
g = B("g")
e = B("e")
h = C("h")
c = C("c")

l.w = g
a.s = h
f.q = g
j.q = g
g.s = h
e.s = h
h.q = a
c.q = e
assert e.s.q.s.q.s.txt == "h"