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

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

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

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

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

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

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