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

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

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

e.q = g
e.t = g
a.x = e
a.r = e
g.q = e
g.t = e
assert e.q.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.t: A = None
        self.txt = txt

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

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

e.q = g
e.t = g
a.x = e
a.r = e
g.q = e
g.t = e
assert e.q.t.t.txt == "g"