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

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

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

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

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

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

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

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

m.t = k
m.q = k
m.o = j
f.t = d
f.p = m
j.t = m
e.t = m
d.t = f
d.p = m
g.t = m
k.t = f
k.p = m
a.t = m
assert k.t.t.p.o.t.q.t.txt == "f"