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

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

g = A("g")
j = B("j")
e = A("e")
k = A("k")
i = B("i")
a = B("a")

g.q = i
g.s = j
j.x = e
e.q = i
e.s = a
k.q = j
k.s = j
i.x = e
a.x = g
assert k.q.x.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.txt = txt

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

g = A("g")
j = B("j")
e = A("e")
k = A("k")
i = B("i")
a = B("a")

g.q = i
g.s = j
j.x = e
e.q = i
e.s = a
k.q = j
k.s = j
i.x = e
a.x = g
assert k.q.x.q.x.txt == "e"