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

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

d = A("d")
c = B("c")
h = A("h")
f = A("f")
k = B("k")
i = A("i")
m = B("m")
n = A("n")
g = A("g")

d.s = n
c.p = k
c.z = k
h.s = n
f.s = d
k.p = c
k.z = c
i.s = n
m.p = k
m.z = c
n.s = g
g.s = h
assert f.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.p: B = None
        self.z: B = None
        self.txt = txt

d = A("d")
c = B("c")
h = A("h")
f = A("f")
k = B("k")
i = A("i")
m = B("m")
n = A("n")
g = A("g")

d.s = n
c.p = k
c.z = k
h.s = n
f.s = d
k.p = c
k.z = c
i.s = n
m.p = k
m.z = c
n.s = g
g.s = h
assert f.s.s.s.s.s.s.txt == "g"