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

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

k = A("k")
m = B("m")
g = A("g")
a = A("a")
n = A("n")
h = A("h")
l = B("l")

k.s = g
m.t = h
g.s = k
a.s = g
n.s = g
h.s = n
l.t = g
assert g.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.t: A = None
        self.txt = txt

k = A("k")
m = B("m")
g = A("g")
a = A("a")
n = A("n")
h = A("h")
l = B("l")

k.s = g
m.t = h
g.s = k
a.s = g
n.s = g
h.s = n
l.t = g
assert g.s.s.s.s.s.txt == "k"