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

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

g = A("g")
n = B("n")
e = B("e")
j = A("j")
l = B("l")

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

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

g = A("g")
n = B("n")
e = B("e")
j = A("j")
l = B("l")

g.o = l
g.q = e
n.o = l
e.o = l
j.o = e
j.q = n
l.o = e
assert g.q.o.o.txt == "e"