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

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

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

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

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

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