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

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

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

d = A("d")
i = B("i")
f = C("f")

d.p = i
i.z = d
i.r = f
f.p = d
f.q = d
f.x = i
assert d.p.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

d = A("d")
i = B("i")
f = C("f")

d.p = i
i.z = d
i.r = f
f.p = d
f.q = d
f.x = i
assert d.p.r.q.txt == "d"