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

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

j = A("j")
m = B("m")
i = B("i")
d = A("d")
l = A("l")
b = B("b")
a = A("a")

j.u = l
m.w = j
m.y = j
i.w = j
i.y = d
d.u = a
l.u = j
b.w = d
b.y = l
a.u = j
assert i.w.u.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.w: A = None
        self.y: A = None
        self.txt = txt

j = A("j")
m = B("m")
i = B("i")
d = A("d")
l = A("l")
b = B("b")
a = A("a")

j.u = l
m.w = j
m.y = j
i.w = j
i.y = d
d.u = a
l.u = j
b.w = d
b.y = l
a.u = j
assert i.w.u.u.u.u.txt == "j"