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

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

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

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

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

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

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