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

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

j = A("j")
i = B("i")
a = A("a")
g = B("g")

j.o = a
i.q = a
i.u = g
a.o = j
g.q = j
g.u = i
assert a.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

j = A("j")
i = B("i")
a = A("a")
g = B("g")

j.o = a
i.q = a
i.u = g
a.o = j
g.q = j
g.u = i
assert a.o.o.o.txt == "j"