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

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

a = A("a")
m = B("m")
c = A("c")
i = A("i")
g = A("g")
l = A("l")
n = A("n")
d = A("d")
e = B("e")
f = A("f")

a.u = d
m.v = e
c.u = a
i.u = f
g.u = a
l.u = f
n.u = i
d.u = g
e.v = m
f.u = l
assert n.u.u.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.v: B = None
        self.txt = txt

a = A("a")
m = B("m")
c = A("c")
i = A("i")
g = A("g")
l = A("l")
n = A("n")
d = A("d")
e = B("e")
f = A("f")

a.u = d
m.v = e
c.u = a
i.u = f
g.u = a
l.u = f
n.u = i
d.u = g
e.v = m
f.u = l
assert n.u.u.u.u.u.u.u.u.txt == "f"