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

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

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

g = A("g")
h = B("h")
b = C("b")
j = C("j")
a = A("a")
c = A("c")
e = A("e")

g.w = h
h.u = c
b.u = h
b.q = j
b.w = j
j.u = h
j.q = b
j.w = b
a.w = h
c.w = h
e.w = h
assert b.u.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
b = C("b")
j = C("j")
a = A("a")
c = A("c")
e = A("e")

g.w = h
h.u = c
b.u = h
b.q = j
b.w = j
j.u = h
j.q = b
j.w = b
a.w = h
c.w = h
e.w = h
assert b.u.u.w.txt == "h"