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

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

n = A("n")
f = B("f")
b = A("b")
e = B("e")
j = B("j")
g = B("g")
a = B("a")
h = B("h")

n.s = b
n.z = b
f.s = b
f.p = e
b.s = n
b.z = n
e.s = n
e.p = f
j.s = b
j.p = h
g.s = n
g.p = f
a.s = b
a.p = e
h.s = b
h.p = j
assert f.s.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.z: A = None
        self.txt = txt

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

n = A("n")
f = B("f")
b = A("b")
e = B("e")
j = B("j")
g = B("g")
a = B("a")
h = B("h")

n.s = b
n.z = b
f.s = b
f.p = e
b.s = n
b.z = n
e.s = n
e.p = f
j.s = b
j.p = h
g.s = n
g.p = f
a.s = b
a.p = e
h.s = b
h.p = j
assert f.s.s.z.txt == "b"