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

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

a = A("a")
k = B("k")
g = A("g")
e = B("e")
h = A("h")
m = A("m")

a.t = e
a.q = k
k.y = g
g.t = k
g.q = k
e.y = a
h.t = e
h.q = k
m.t = k
m.q = e
assert e.y.t.y.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
g = A("g")
e = B("e")
h = A("h")
m = A("m")

a.t = e
a.q = k
k.y = g
g.t = k
g.q = k
e.y = a
h.t = e
h.q = k
m.t = k
m.q = e
assert e.y.t.y.q.y.q.txt == "k"