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

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

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

h = A("h")
i = B("i")
a = C("a")
m = A("m")

h.t = m
h.z = i
h.o = i
i.t = m
a.q = m
m.t = h
m.z = i
m.o = i
assert a.q.t.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.z: B = None
        self.o: B = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
a = C("a")
m = A("m")

h.t = m
h.z = i
h.o = i
i.t = m
a.q = m
m.t = h
m.z = i
m.o = i
assert a.q.t.o.t.txt == "m"