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

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

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

d = A("d")
i = B("i")
c = C("c")
m = A("m")

d.p = i
d.z = i
d.t = m
i.z = c
c.q = i
c.t = i
m.p = i
m.z = i
m.t = d
assert i.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.z: B = None
        self.t: A = None
        self.txt = txt

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

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

d = A("d")
i = B("i")
c = C("c")
m = A("m")

d.p = i
d.z = i
d.t = m
i.z = c
c.q = i
c.t = i
m.p = i
m.z = i
m.t = d
assert i.z.q.z.txt == "c"