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

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

n = A("n")
l = B("l")
b = A("b")
f = A("f")
h = B("h")

n.u = b
n.w = l
l.w = h
b.u = f
b.w = h
f.u = n
f.w = h
h.w = l
assert n.u.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.w: B = None
        self.txt = txt

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

n = A("n")
l = B("l")
b = A("b")
f = A("f")
h = B("h")

n.u = b
n.w = l
l.w = h
b.u = f
b.w = h
f.u = n
f.w = h
h.w = l
assert n.u.w.w.w.txt == "h"