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

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

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

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

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

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

l.s = h
l.r = m
n.r = i
h.s = m
h.r = m
k.r = m
g.r = i
j.r = h
b.r = h
a.r = m
m.s = h
m.r = i
i.s = h
i.r = l
assert k.r.s.s.txt == "m"