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

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

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

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

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

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

n.z = g
l.s = a
l.r = f
d.s = h
d.r = f
h.z = g
g.s = b
g.r = n
e.s = h
e.r = f
b.z = e
f.z = d
a.z = g
assert n.z.r.z.s.z.s.z.r.txt == "n"