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

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

a = A("a")
k = B("k")
l = A("l")
i = B("i")
d = A("d")
j = B("j")
b = B("b")
c = A("c")
f = B("f")

a.r = c
a.v = j
k.r = a
k.w = j
l.r = a
l.v = k
i.r = l
i.w = f
d.r = a
d.v = f
j.r = d
j.w = f
b.r = a
b.w = i
c.r = d
c.v = f
f.r = d
f.w = j
assert j.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.v: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
l = A("l")
i = B("i")
d = A("d")
j = B("j")
b = B("b")
c = A("c")
f = B("f")

a.r = c
a.v = j
k.r = a
k.w = j
l.r = a
l.v = k
i.r = l
i.w = f
d.r = a
d.v = f
j.r = d
j.w = f
b.r = a
b.w = i
c.r = d
c.v = f
f.r = d
f.w = j
assert j.r.r.r.r.txt == "d"