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

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

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

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

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

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

k.r = m
a.o = k
a.w = m
j.o = m
j.w = k
m.r = k
i.o = k
i.w = k
assert i.w.r.r.r.r.txt == "k"