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

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

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

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

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

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

d.u = a
d.v = m
b.r = m
b.w = d
l.u = c
l.v = m
g.r = m
g.w = h
h.u = b
h.v = d
a.r = m
a.w = d
c.r = l
c.w = m
m.u = c
m.v = d
assert d.u.r.u.r.u.w.u.txt == "c"