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

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

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

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

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

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

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