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

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

f = A("f")
h = B("h")
j = A("j")
l = A("l")
i = A("i")
b = B("b")
g = A("g")

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

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

f = A("f")
h = B("h")
j = A("j")
l = A("l")
i = A("i")
b = B("b")
g = A("g")

f.r = l
f.v = l
h.v = f
j.r = i
j.v = g
l.r = j
l.v = g
i.r = g
i.v = g
b.v = j
g.r = f
g.v = l
assert h.v.v.v.v.r.r.r.txt == "g"