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

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

n = A("n")
a = B("a")
c = B("c")
f = B("f")
l = B("l")
i = B("i")
k = B("k")
d = A("d")
j = B("j")

n.v = d
a.y = k
c.y = j
f.y = k
l.y = f
i.y = f
k.y = j
d.v = n
j.y = f
assert a.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

n = A("n")
a = B("a")
c = B("c")
f = B("f")
l = B("l")
i = B("i")
k = B("k")
d = A("d")
j = B("j")

n.v = d
a.y = k
c.y = j
f.y = k
l.y = f
i.y = f
k.y = j
d.v = n
j.y = f
assert a.y.y.y.y.y.txt == "j"