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.x: A = None
        self.txt = txt

n = A("n")
j = B("j")
a = B("a")

n.p = a
j.z = n
j.x = n
a.z = n
a.x = n
assert j.x.p.x.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.x: A = None
        self.txt = txt

n = A("n")
j = B("j")
a = B("a")

n.p = a
j.z = n
j.x = n
a.z = n
a.x = n
assert j.x.p.x.txt == "n"