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

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

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

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

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

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

i.s = h
b.q = n
b.v = e
h.s = f
a.q = i
a.v = b
k.q = n
k.v = a
e.q = i
e.v = b
n.s = i
j.s = f
f.s = h
assert b.q.s.s.s.s.s.s.s.s.txt == "h"