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

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

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

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

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

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

c.r = i
c.v = g
l.r = b
j.r = c
h.r = i
h.v = g
i.r = b
g.r = l
g.v = k
d.r = i
d.v = b
k.r = i
k.v = c
b.r = l
b.v = h
assert d.v.v.r.r.r.r.txt == "b"