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

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

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

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

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

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

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