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.txt = txt

d = A("d")
c = B("c")
f = B("f")
m = A("m")
j = A("j")
k = B("k")
h = B("h")
l = B("l")

d.u = j
c.w = m
f.w = d
m.u = j
j.u = m
k.w = m
h.w = j
l.w = d
assert l.w.u.u.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.txt = txt

d = A("d")
c = B("c")
f = B("f")
m = A("m")
j = A("j")
k = B("k")
h = B("h")
l = B("l")

d.u = j
c.w = m
f.w = d
m.u = j
j.u = m
k.w = m
h.w = j
l.w = d
assert l.w.u.u.u.u.u.u.txt == "m"