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

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

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

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

a.t = c
a.q = c
d.r = a
d.u = g
d.w = h
g.u = c
h.r = a
h.u = c
h.w = d
b.r = a
b.u = c
b.w = d
c.u = g
assert d.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.q: C = None
        self.txt = txt

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

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

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

a.t = c
a.q = c
d.r = a
d.u = g
d.w = h
g.u = c
h.r = a
h.u = c
h.w = d
b.r = a
b.u = c
b.w = d
c.u = g
assert d.u.u.u.u.u.txt == "g"