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

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

a = A("a")
c = B("c")
m = A("m")
h = B("h")
n = B("n")
b = B("b")
d = B("d")
k = B("k")
j = A("j")
g = B("g")

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

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

a = A("a")
c = B("c")
m = A("m")
h = B("h")
n = B("n")
b = B("b")
d = B("d")
k = B("k")
j = A("j")
g = B("g")

a.w = h
a.v = m
c.w = h
m.w = h
m.v = j
h.w = k
n.w = g
b.w = k
d.w = g
k.w = c
j.w = n
j.v = m
g.w = n
assert b.w.w.w.w.w.w.w.w.w.txt == "h"