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.z: B = None
        self.txt = txt

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

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

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

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