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

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

i = A("i")
g = B("g")
k = A("k")
n = A("n")
j = A("j")

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

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

i = A("i")
g = B("g")
k = A("k")
n = A("n")
j = A("j")

i.w = n
i.q = n
g.t = i
k.w = i
k.q = j
n.w = i
n.q = j
j.w = k
j.q = i
assert i.q.w.q.w.w.txt == "n"