class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

g = A("g")
a = B("a")
c = C("c")
k = B("k")
m = B("m")
d = B("d")
e = A("e")

g.o = c
a.t = g
a.q = c
c.r = a
k.t = e
k.q = c
m.t = e
m.q = c
d.t = e
d.q = c
e.o = c
assert a.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

g = A("g")
a = B("a")
c = C("c")
k = B("k")
m = B("m")
d = B("d")
e = A("e")

g.o = c
a.t = g
a.q = c
c.r = a
k.t = e
k.q = c
m.t = e
m.q = c
d.t = e
d.q = c
e.o = c
assert a.q.r.q.txt == "c"