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

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

a = A("a")
d = B("d")
n = A("n")
c = B("c")
f = B("f")
h = A("h")
l = B("l")
m = A("m")
i = B("i")
j = B("j")

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

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

a = A("a")
d = B("d")
n = A("n")
c = B("c")
f = B("f")
h = A("h")
l = B("l")
m = A("m")
i = B("i")
j = B("j")

a.v = m
d.r = f
n.v = h
c.r = l
f.r = d
h.v = a
l.r = d
m.v = a
i.r = j
j.r = d
assert i.r.r.r.r.r.r.txt == "d"