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

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

b = A("b")
h = B("h")
e = A("e")
m = A("m")
k = B("k")
f = A("f")
a = A("a")

b.o = m
h.w = a
e.o = b
m.o = f
k.w = e
f.o = e
a.o = f
assert k.w.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

b = A("b")
h = B("h")
e = A("e")
m = A("m")
k = B("k")
f = A("f")
a = A("a")

b.o = m
h.w = a
e.o = b
m.o = f
k.w = e
f.o = e
a.o = f
assert k.w.o.o.txt == "m"