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

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

g = A("g")
e = B("e")
i = A("i")
j = A("j")
a = A("a")
l = B("l")
h = A("h")
d = B("d")

g.s = h
e.z = l
i.s = h
j.s = h
a.s = j
l.z = e
h.s = j
d.z = l
assert l.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

g = A("g")
e = B("e")
i = A("i")
j = A("j")
a = A("a")
l = B("l")
h = A("h")
d = B("d")

g.s = h
e.z = l
i.s = h
j.s = h
a.s = j
l.z = e
h.s = j
d.z = l
assert l.z.z.z.z.txt == "l"