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

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

d = A("d")
g = B("g")
f = A("f")
n = A("n")
m = B("m")
i = B("i")
b = A("b")

d.u = n
g.x = m
g.w = n
f.u = b
n.u = f
m.x = g
m.w = f
i.x = g
i.w = f
b.u = f
assert f.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.x: B = None
        self.w: A = None
        self.txt = txt

d = A("d")
g = B("g")
f = A("f")
n = A("n")
m = B("m")
i = B("i")
b = A("b")

d.u = n
g.x = m
g.w = n
f.u = b
n.u = f
m.x = g
m.w = f
i.x = g
i.w = f
b.u = f
assert f.u.u.u.txt == "b"