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

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

j = A("j")
k = B("k")
n = B("n")
i = A("i")
h = A("h")
d = A("d")

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

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

j = A("j")
k = B("k")
n = B("n")
i = A("i")
h = A("h")
d = A("d")

j.q = h
j.w = i
k.w = n
k.p = n
n.w = k
n.p = k
i.q = h
i.w = h
h.q = j
h.w = j
d.q = i
d.w = i
assert h.w.w.q.w.txt == "j"