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

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

e = A("e")
n = B("n")
d = A("d")
g = A("g")
f = A("f")
b = B("b")
k = A("k")
l = B("l")
m = A("m")
i = B("i")

e.s = m
n.r = k
n.x = b
d.s = f
g.s = f
f.s = d
b.r = d
b.x = n
k.s = d
l.r = m
l.x = i
m.s = f
i.r = f
i.x = n
assert k.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.r: A = None
        self.x: B = None
        self.txt = txt

e = A("e")
n = B("n")
d = A("d")
g = A("g")
f = A("f")
b = B("b")
k = A("k")
l = B("l")
m = A("m")
i = B("i")

e.s = m
n.r = k
n.x = b
d.s = f
g.s = f
f.s = d
b.r = d
b.x = n
k.s = d
l.r = m
l.x = i
m.s = f
i.r = f
i.x = n
assert k.s.s.s.s.s.s.s.s.txt == "f"