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

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

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

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

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

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

b.w = a
g.w = e
g.v = m
m.w = n
m.v = g
n.w = b
e.w = n
i.w = n
f.w = i
a.w = f
assert g.v.v.w.w.w.w.txt == "a"