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

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

e = A("e")
m = B("m")
j = A("j")
a = B("a")
d = B("d")
k = B("k")
f = B("f")
h = B("h")

e.v = j
m.s = d
j.v = e
a.s = m
d.s = k
k.s = f
f.s = d
h.s = a
assert h.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

e = A("e")
m = B("m")
j = A("j")
a = B("a")
d = B("d")
k = B("k")
f = B("f")
h = B("h")

e.v = j
m.s = d
j.v = e
a.s = m
d.s = k
k.s = f
f.s = d
h.s = a
assert h.s.s.s.s.txt == "k"