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

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

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

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

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

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

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