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

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

d = A("d")
n = B("n")
j = A("j")
h = B("h")
e = B("e")
m = A("m")
c = A("c")

d.w = c
n.t = j
n.q = h
j.w = m
h.t = m
h.q = n
e.t = c
e.q = h
m.w = c
c.w = j
assert n.q.q.t.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

d = A("d")
n = B("n")
j = A("j")
h = B("h")
e = B("e")
m = A("m")
c = A("c")

d.w = c
n.t = j
n.q = h
j.w = m
h.t = m
h.q = n
e.t = c
e.q = h
m.w = c
c.w = j
assert n.q.q.t.w.w.w.txt == "j"