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

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

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

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

d.q = n
b.u = h
m.z = n
f.u = h
n.z = m
h.q = n
assert b.u.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

d.q = n
b.u = h
m.z = n
f.u = h
n.z = m
h.q = n
assert b.u.q.z.txt == "m"