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

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

n = A("n")
j = B("j")
h = B("h")
d = B("d")
i = B("i")
g = A("g")
b = B("b")

n.u = g
j.u = n
j.w = h
h.u = g
h.w = i
d.u = g
d.w = i
i.u = g
i.w = h
g.u = n
b.u = g
b.w = j
assert j.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

n = A("n")
j = B("j")
h = B("h")
d = B("d")
i = B("i")
g = A("g")
b = B("b")

n.u = g
j.u = n
j.w = h
h.u = g
h.w = i
d.u = g
d.w = i
i.u = g
i.w = h
g.u = n
b.u = g
b.w = j
assert j.u.u.u.txt == "n"