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

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

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

g.u = d
g.q = l
l.t = g
l.z = g
d.t = g
d.z = g
assert g.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.q: B = None
        self.txt = txt

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

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

g.u = d
g.q = l
l.t = g
l.z = g
d.t = g
d.z = g
assert g.u.z.u.txt == "d"