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

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

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

d = A("d")
n = B("n")
h = C("h")

d.t = n
n.u = d
n.v = h
h.z = n
h.q = d
h.v = d
assert h.z.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

d = A("d")
n = B("n")
h = C("h")

d.t = n
n.u = d
n.v = h
h.z = n
h.q = d
h.v = d
assert h.z.v.q.txt == "d"