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.p: A = None
        self.txt = txt

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

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

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

h.s = n
a.s = g
a.p = g
k.s = n
k.p = g
e.s = g
e.p = n
g.s = h
f.s = g
f.p = g
l.s = n
l.p = g
n.s = g
assert k.s.s.s.s.s.s.s.txt == "n"