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

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

k = A("k")
j = B("j")
i = A("i")
f = B("f")
h = B("h")

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

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

k = A("k")
j = B("j")
i = A("i")
f = B("f")
h = B("h")

k.w = i
j.o = f
i.w = k
f.o = j
h.o = f
assert h.o.o.o.o.o.txt == "f"