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

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

c = A("c")
d = B("d")
n = B("n")
h = A("h")
a = B("a")
e = A("e")

c.w = e
d.q = c
d.t = n
n.q = c
n.t = a
h.w = c
a.q = c
a.t = d
e.w = h
assert a.t.q.w.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.q: A = None
        self.t: B = None
        self.txt = txt

c = A("c")
d = B("d")
n = B("n")
h = A("h")
a = B("a")
e = A("e")

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