class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: A = 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")
c = B("c")
m = A("m")

n.p = c
n.s = m
c.y = n
c.z = m
m.p = c
m.s = n
assert n.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: A = 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")
c = B("c")
m = A("m")

n.p = c
n.s = m
c.y = n
c.z = m
m.p = c
m.s = n
assert n.p.y.p.txt == "c"