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

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

m = A("m")
l = B("l")
d = B("d")
c = A("c")
i = B("i")
j = B("j")
h = B("h")
k = B("k")

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

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

m = A("m")
l = B("l")
d = B("d")
c = A("c")
i = B("i")
j = B("j")
h = B("h")
k = B("k")

m.w = c
l.v = m
l.u = d
d.v = m
d.u = h
c.w = m
i.v = m
i.u = d
j.v = m
j.u = k
h.v = m
h.u = k
k.v = c
k.u = i
assert j.u.v.w.txt == "m"