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

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

d = A("d")
i = B("i")
e = A("e")
g = A("g")
m = A("m")
l = B("l")
a = A("a")
f = A("f")
b = B("b")

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

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

d = A("d")
i = B("i")
e = A("e")
g = A("g")
m = A("m")
l = B("l")
a = A("a")
f = A("f")
b = B("b")

d.o = i
i.w = e
i.o = e
e.o = i
g.o = b
m.o = l
l.w = f
l.o = m
a.o = l
f.o = b
b.w = g
b.o = f
assert a.o.o.o.o.o.w.o.txt == "b"