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

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

m = A("m")
g = B("g")
d = B("d")
a = A("a")
l = A("l")
c = A("c")
k = A("k")
i = A("i")

m.v = d
g.w = l
g.v = c
d.w = l
d.v = m
a.v = g
l.v = g
c.v = g
k.v = d
i.v = d
assert a.v.w.v.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

m = A("m")
g = B("g")
d = B("d")
a = A("a")
l = A("l")
c = A("c")
k = A("k")
i = A("i")

m.v = d
g.w = l
g.v = c
d.w = l
d.v = m
a.v = g
l.v = g
c.v = g
k.v = d
i.v = d
assert a.v.w.v.w.v.txt == "g"