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

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

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

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

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

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

j.w = k
j.y = k
i.o = j
i.z = a
k.w = j
k.y = j
a.o = j
a.z = i
assert a.o.y.w.txt == "j"