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

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

l = A("l")
n = B("n")
j = A("j")
k = A("k")
m = B("m")
g = A("g")

l.o = n
l.q = k
n.x = l
j.o = m
j.q = l
k.o = m
k.q = g
m.x = l
g.o = m
g.q = l
assert n.x.o.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.q: A = None
        self.txt = txt

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

l = A("l")
n = B("n")
j = A("j")
k = A("k")
m = B("m")
g = A("g")

l.o = n
l.q = k
n.x = l
j.o = m
j.q = l
k.o = m
k.q = g
m.x = l
g.o = m
g.q = l
assert n.x.o.x.o.txt == "n"