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

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

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

e.q = g
l.p = e
l.r = e
g.q = e
assert e.q.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.p: A = None
        self.r: A = None
        self.txt = txt

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

e.q = g
l.p = e
l.r = e
g.q = e
assert e.q.q.q.txt == "g"