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

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

k = A("k")
i = B("i")
d = A("d")
e = A("e")
g = B("g")
b = A("b")
c = B("c")

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

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

k = A("k")
i = B("i")
d = A("d")
e = A("e")
g = B("g")
b = A("b")
c = B("c")

k.q = b
k.s = g
i.p = c
i.x = k
d.q = e
d.s = i
e.q = k
e.s = c
g.p = i
g.x = k
b.q = k
b.s = i
c.p = i
c.x = b
assert e.s.x.q.q.s.txt == "i"