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

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

i = A("i")
e = B("e")
h = B("h")
g = A("g")
m = A("m")
k = A("k")
n = B("n")

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

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

i = A("i")
e = B("e")
h = B("h")
g = A("g")
m = A("m")
k = A("k")
n = B("n")

i.r = m
i.s = h
e.r = h
h.r = e
g.r = k
g.s = h
m.r = k
m.s = h
k.r = m
k.s = n
n.r = h
assert m.r.s.r.r.r.r.r.txt == "h"