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

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

n = A("n")
l = B("l")
e = A("e")
b = B("b")
g = B("g")
h = B("h")
a = A("a")
m = B("m")
j = A("j")

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

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

n = A("n")
l = B("l")
e = A("e")
b = B("b")
g = B("g")
h = B("h")
a = A("a")
m = B("m")
j = A("j")

n.y = b
n.o = j
l.q = a
e.y = h
e.o = j
b.q = n
g.q = e
h.q = j
a.y = m
a.o = j
m.q = j
j.y = g
j.o = a
assert h.q.o.y.txt == "m"