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.t: A = None
        self.z: A = None
        self.txt = txt

a = A("a")
g = B("g")
m = A("m")
l = A("l")
d = A("d")
f = A("f")
b = B("b")
i = A("i")

a.s = f
a.v = l
g.t = l
g.z = i
m.s = a
m.v = i
l.s = a
l.v = m
d.s = l
d.v = i
f.s = l
f.v = a
b.t = m
b.z = f
i.s = f
i.v = f
assert a.v.s.v.s.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.t: A = None
        self.z: A = None
        self.txt = txt

a = A("a")
g = B("g")
m = A("m")
l = A("l")
d = A("d")
f = A("f")
b = B("b")
i = A("i")

a.s = f
a.v = l
g.t = l
g.z = i
m.s = a
m.v = i
l.s = a
l.v = m
d.s = l
d.v = i
f.s = l
f.v = a
b.t = m
b.z = f
i.s = f
i.v = f
assert a.v.s.v.s.txt == "a"