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

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

k = A("k")
n = B("n")
e = B("e")
g = A("g")
d = B("d")
b = B("b")

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

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

k = A("k")
n = B("n")
e = B("e")
g = A("g")
d = B("d")
b = B("b")

k.t = b
k.q = g
n.x = k
n.s = e
e.x = k
e.s = b
g.t = d
g.q = k
d.x = g
d.s = n
b.x = k
b.s = d
assert b.s.s.x.t.x.q.txt == "g"