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

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

f = A("f")
k = B("k")
d = A("d")
b = A("b")
l = A("l")
n = B("n")

f.u = k
f.v = d
k.u = n
d.u = n
d.v = f
b.u = k
b.v = l
l.u = n
l.v = b
n.u = k
assert k.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: A = None
        self.txt = txt

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

f = A("f")
k = B("k")
d = A("d")
b = A("b")
l = A("l")
n = B("n")

f.u = k
f.v = d
k.u = n
d.u = n
d.v = f
b.u = k
b.v = l
l.u = n
l.v = b
n.u = k
assert k.u.u.u.u.u.txt == "n"