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

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

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

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

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

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

e.p = c
e.z = n
n.p = e
n.z = e
c.p = e
c.z = n
assert n.p.z.z.txt == "e"