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

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

b = A("b")
f = B("f")
m = A("m")
c = B("c")
n = A("n")
k = B("k")
j = B("j")
a = B("a")
l = A("l")
h = A("h")

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

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

b = A("b")
f = B("f")
m = A("m")
c = B("c")
n = A("n")
k = B("k")
j = B("j")
a = B("a")
l = A("l")
h = A("h")

b.r = a
f.r = a
f.v = j
m.r = c
c.r = k
c.v = f
n.r = j
k.r = c
k.v = f
j.r = f
j.v = a
a.r = c
a.v = c
l.r = a
h.r = k
assert m.r.v.v.r.v.r.v.r.v.r.txt == "f"