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

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

m = A("m")
g = B("g")
h = A("h")
b = B("b")
k = A("k")
d = B("d")
f = B("f")
i = A("i")
j = B("j")

m.o = k
g.o = k
g.v = k
h.o = m
b.o = h
b.v = h
k.o = m
d.o = k
d.v = m
f.o = i
f.v = h
i.o = m
j.o = i
j.v = h
assert b.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.o: A = None
        self.v: A = None
        self.txt = txt

m = A("m")
g = B("g")
h = A("h")
b = B("b")
k = A("k")
d = B("d")
f = B("f")
i = A("i")
j = B("j")

m.o = k
g.o = k
g.v = k
h.o = m
b.o = h
b.v = h
k.o = m
d.o = k
d.v = m
f.o = i
f.v = h
i.o = m
j.o = i
j.v = h
assert b.o.o.o.o.o.o.o.txt == "k"