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

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

c = A("c")
n = B("n")
d = A("d")

c.z = n
c.p = d
n.w = c
d.z = n
d.p = c
assert n.w.z.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.p: A = None
        self.txt = txt

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

c = A("c")
n = B("n")
d = A("d")

c.z = n
c.p = d
n.w = c
d.z = n
d.p = c
assert n.w.z.w.txt == "c"