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

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

a = A("a")
g = B("g")
j = A("j")
f = B("f")
n = A("n")

a.w = g
g.t = f
g.q = n
j.w = g
f.t = g
f.q = j
n.w = g
assert j.w.t.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

a = A("a")
g = B("g")
j = A("j")
f = B("f")
n = A("n")

a.w = g
g.t = f
g.q = n
j.w = g
f.t = g
f.q = j
n.w = g
assert j.w.t.q.w.q.txt == "n"