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

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

j = A("j")
k = B("k")
l = A("l")
g = A("g")
c = B("c")
a = A("a")

j.q = k
k.z = l
k.x = a
l.q = c
g.q = c
c.z = a
c.x = j
a.q = k
assert g.q.x.q.z.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

j = A("j")
k = B("k")
l = A("l")
g = A("g")
c = B("c")
a = A("a")

j.q = k
k.z = l
k.x = a
l.q = c
g.q = c
c.z = a
c.x = j
a.q = k
assert g.q.x.q.z.q.x.txt == "j"