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

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

g = A("g")
m = B("m")
l = A("l")
c = A("c")

g.q = c
m.z = g
l.q = g
c.q = g
assert g.q.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.z: A = None
        self.txt = txt

g = A("g")
m = B("m")
l = A("l")
c = A("c")

g.q = c
m.z = g
l.q = g
c.q = g
assert g.q.q.q.q.txt == "g"