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

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

f = A("f")
m = B("m")
h = A("h")
d = A("d")
c = B("c")
b = B("b")
g = B("g")
a = A("a")

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

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

f = A("f")
m = B("m")
h = A("h")
d = A("d")
c = B("c")
b = B("b")
g = B("g")
a = A("a")

f.u = g
f.w = g
m.w = a
m.o = c
h.u = g
h.w = g
d.u = g
d.w = g
c.w = f
c.o = m
b.w = h
b.o = g
g.w = h
g.o = b
a.u = c
a.w = b
assert d.u.o.w.w.w.w.txt == "g"