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

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

i = A("i")
k = B("k")
n = A("n")
h = B("h")
m = B("m")
g = A("g")
j = B("j")
d = B("d")
l = B("l")

i.s = n
i.x = j
k.r = j
k.s = g
n.s = g
n.x = h
h.r = m
h.s = g
m.r = h
m.s = n
g.s = n
g.x = j
j.r = k
j.s = i
d.r = k
d.s = n
l.r = m
l.s = g
assert h.r.r.r.r.r.r.r.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.x: B = None
        self.txt = txt

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

i = A("i")
k = B("k")
n = A("n")
h = B("h")
m = B("m")
g = A("g")
j = B("j")
d = B("d")
l = B("l")

i.s = n
i.x = j
k.r = j
k.s = g
n.s = g
n.x = h
h.r = m
h.s = g
m.r = h
m.s = n
g.s = n
g.x = j
j.r = k
j.s = i
d.r = k
d.s = n
l.r = m
l.s = g
assert h.r.r.r.r.r.r.r.s.s.txt == "g"