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

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

k = A("k")
f = B("f")
l = A("l")
m = B("m")
j = B("j")
b = B("b")
a = A("a")
e = B("e")
i = B("i")
h = B("h")

k.w = i
k.r = a
f.x = k
f.y = m
l.w = h
l.r = k
m.x = l
m.y = h
j.x = k
j.y = e
b.x = l
b.y = f
a.w = h
a.r = k
e.x = a
e.y = h
i.x = a
i.y = j
h.x = k
h.y = m
assert m.y.y.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: A = None
        self.txt = txt

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

k = A("k")
f = B("f")
l = A("l")
m = B("m")
j = B("j")
b = B("b")
a = A("a")
e = B("e")
i = B("i")
h = B("h")

k.w = i
k.r = a
f.x = k
f.y = m
l.w = h
l.r = k
m.x = l
m.y = h
j.x = k
j.y = e
b.x = l
b.y = f
a.w = h
a.r = k
e.x = a
e.y = h
i.x = a
i.y = j
h.x = k
h.y = m
assert m.y.y.y.x.txt == "k"