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

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

k = A("k")
l = B("l")
a = A("a")
d = A("d")
h = B("h")
c = A("c")
g = A("g")
e = B("e")
n = B("n")
f = B("f")

k.w = g
k.r = a
l.v = a
a.w = g
a.r = c
d.w = k
d.r = c
h.v = c
c.w = a
c.r = a
g.w = d
g.r = a
e.v = d
n.v = g
f.v = k
assert h.v.w.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.r: A = None
        self.txt = txt

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

k = A("k")
l = B("l")
a = A("a")
d = A("d")
h = B("h")
c = A("c")
g = A("g")
e = B("e")
n = B("n")
f = B("f")

k.w = g
k.r = a
l.v = a
a.w = g
a.r = c
d.w = k
d.r = c
h.v = c
c.w = a
c.r = a
g.w = d
g.r = a
e.v = d
n.v = g
f.v = k
assert h.v.w.r.r.txt == "a"