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

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

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

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

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

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

k.o = j
d.v = j
d.r = i
j.o = k
b.v = j
b.r = d
m.o = k
c.v = a
c.r = h
a.o = m
h.v = k
h.r = d
l.v = a
l.r = h
i.v = m
i.r = b
assert j.o.o.o.o.o.o.o.o.o.txt == "k"