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

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

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

h.y = j
h.q = b
i.o = k
g.o = i
b.o = g
j.y = e
j.q = g
e.y = h
e.q = i
k.o = i
m.o = g
assert i.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: B = None
        self.txt = txt

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

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

h.y = j
h.q = b
i.o = k
g.o = i
b.o = g
j.y = e
j.q = g
e.y = h
e.q = i
k.o = i
m.o = g
assert i.o.o.o.txt == "k"