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

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

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

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

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

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

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