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

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

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

n.x = d
n.s = k
l.t = m
m.x = n
m.s = n
k.x = g
k.s = g
b.x = k
b.s = k
e.t = b
d.x = n
d.s = g
g.x = b
g.s = d
i.t = g
assert n.s.x.s.s.x.x.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.s: A = None
        self.txt = txt

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

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

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