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

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

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

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

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

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

g.s = m
g.v = d
a.z = b
b.z = e
f.s = d
f.v = m
d.s = m
d.v = g
m.s = f
m.v = f
n.z = b
e.z = n
assert d.s.v.s.s.s.v.v.txt == "f"