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

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

d = A("d")
i = B("i")
a = B("a")
k = B("k")
h = A("h")
g = A("g")
m = A("m")

d.o = a
i.w = a
a.w = i
k.w = a
h.o = a
g.o = a
m.o = a
assert i.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

d = A("d")
i = B("i")
a = B("a")
k = B("k")
h = A("h")
g = A("g")
m = A("m")

d.o = a
i.w = a
a.w = i
k.w = a
h.o = a
g.o = a
m.o = a
assert i.w.w.w.txt == "a"