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.v: B = None
        self.txt = txt

d = A("d")
m = B("m")
a = B("a")
f = A("f")
e = B("e")
c = B("c")
h = B("h")
b = B("b")

d.s = f
d.z = f
m.v = a
a.v = c
f.s = d
f.z = d
e.v = h
c.v = h
h.v = a
b.v = h
assert d.s.s.s.s.z.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.v: B = None
        self.txt = txt

d = A("d")
m = B("m")
a = B("a")
f = A("f")
e = B("e")
c = B("c")
h = B("h")
b = B("b")

d.s = f
d.z = f
m.v = a
a.v = c
f.s = d
f.z = d
e.v = h
c.v = h
h.v = a
b.v = h
assert d.s.s.s.s.z.s.s.z.txt == "d"