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

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

g = A("g")
j = B("j")
c = A("c")
m = B("m")
k = A("k")
i = A("i")
n = A("n")

g.s = c
j.s = c
j.z = i
c.s = k
m.s = i
m.z = k
k.s = c
i.s = g
n.s = i
assert k.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.s: A = None
        self.z: A = None
        self.txt = txt

g = A("g")
j = B("j")
c = A("c")
m = B("m")
k = A("k")
i = A("i")
n = A("n")

g.s = c
j.s = c
j.z = i
c.s = k
m.s = i
m.z = k
k.s = c
i.s = g
n.s = i
assert k.s.s.s.s.s.s.txt == "k"