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

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

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

h = A("h")
f = B("f")
g = C("g")
a = C("a")
m = C("m")
i = A("i")
b = B("b")
d = A("d")
n = A("n")

h.z = b
h.t = i
f.q = a
g.p = b
a.p = f
m.p = f
i.z = b
i.t = d
b.q = m
d.z = f
d.t = h
n.z = f
n.t = h
assert m.p.q.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.t: A = None
        self.txt = txt

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

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

h = A("h")
f = B("f")
g = C("g")
a = C("a")
m = C("m")
i = A("i")
b = B("b")
d = A("d")
n = A("n")

h.z = b
h.t = i
f.q = a
g.p = b
a.p = f
m.p = f
i.z = b
i.t = d
b.q = m
d.z = f
d.t = h
n.z = f
n.t = h
assert m.p.q.p.q.txt == "a"