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

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

h = A("h")
b = B("b")
a = B("a")
i = B("i")
g = A("g")
m = B("m")
n = A("n")
k = A("k")
d = A("d")
l = A("l")

h.r = i
b.v = h
b.s = d
a.v = g
a.s = l
i.v = k
i.s = g
g.r = m
m.v = n
m.s = l
n.r = i
k.r = a
d.r = m
l.r = m
assert a.v.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

h = A("h")
b = B("b")
a = B("a")
i = B("i")
g = A("g")
m = B("m")
n = A("n")
k = A("k")
d = A("d")
l = A("l")

h.r = i
b.v = h
b.s = d
a.v = g
a.s = l
i.v = k
i.s = g
g.r = m
m.v = n
m.s = l
n.r = i
k.r = a
d.r = m
l.r = m
assert a.v.r.v.txt == "n"