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

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

k = A("k")
g = B("g")
a = B("a")
f = A("f")
i = B("i")
h = B("h")
n = A("n")
b = B("b")
e = A("e")
d = B("d")

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

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

k = A("k")
g = B("g")
a = B("a")
f = A("f")
i = B("i")
h = B("h")
n = A("n")
b = B("b")
e = A("e")
d = B("d")

k.u = h
g.v = f
a.v = e
f.u = g
i.v = e
h.v = k
n.u = h
b.v = k
e.u = g
d.v = n
assert i.v.u.v.txt == "f"