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

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

c = A("c")
g = B("g")
e = B("e")
i = B("i")
h = A("h")
d = B("d")
j = B("j")
m = A("m")

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

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

c = A("c")
g = B("g")
e = B("e")
i = B("i")
h = A("h")
d = B("d")
j = B("j")
m = A("m")

c.o = g
c.w = m
g.o = i
e.o = g
i.o = g
h.o = j
h.w = c
d.o = j
j.o = g
m.o = e
m.w = c
assert h.w.w.w.w.o.o.o.txt == "i"