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

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

a = A("a")
f = B("f")
b = A("b")
k = B("k")
n = A("n")
c = A("c")
m = A("m")
h = B("h")

a.z = k
a.p = k
f.s = h
b.z = f
b.p = f
k.s = f
n.z = h
n.p = f
c.z = h
c.p = f
m.z = f
m.p = k
h.s = k
assert b.p.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.p: B = None
        self.txt = txt

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

a = A("a")
f = B("f")
b = A("b")
k = B("k")
n = A("n")
c = A("c")
m = A("m")
h = B("h")

a.z = k
a.p = k
f.s = h
b.z = f
b.p = f
k.s = f
n.z = h
n.p = f
c.z = h
c.p = f
m.z = f
m.p = k
h.s = k
assert b.p.s.s.s.s.s.s.s.txt == "h"