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

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

j = A("j")
a = B("a")
b = B("b")
k = A("k")

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

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

j = A("j")
a = B("a")
b = B("b")
k = A("k")

j.w = a
j.z = k
a.w = k
b.w = j
k.w = b
k.z = j
assert a.w.w.w.txt == "j"