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

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

i = A("i")
g = B("g")
a = B("a")
c = A("c")
d = A("d")
e = A("e")
m = A("m")
n = A("n")

i.s = g
g.s = d
g.x = c
a.s = n
a.x = m
c.s = g
d.s = a
e.s = g
m.s = g
n.s = g
assert d.s.x.s.s.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

i = A("i")
g = B("g")
a = B("a")
c = A("c")
d = A("d")
e = A("e")
m = A("m")
n = A("n")

i.s = g
g.s = d
g.x = c
a.s = n
a.x = m
c.s = g
d.s = a
e.s = g
m.s = g
n.s = g
assert d.s.x.s.s.s.x.txt == "m"