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

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

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

n.w = a
a.z = n
a.v = k
k.z = n
k.v = a
assert n.w.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

n.w = a
a.z = n
a.v = k
k.z = n
k.v = a
assert n.w.v.v.txt == "a"