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

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

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

h = A("h")
i = B("i")
g = C("g")
j = C("j")

h.q = i
i.p = h
i.r = j
g.u = i
g.w = h
g.t = j
j.u = i
j.w = h
j.t = g
assert h.q.r.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
g = C("g")
j = C("j")

h.q = i
i.p = h
i.r = j
g.u = i
g.w = h
g.t = j
j.u = i
j.w = h
j.t = g
assert h.q.r.u.r.txt == "j"