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

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

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

j = A("j")
h = B("h")
d = C("d")
c = B("c")
g = C("g")

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

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

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

j = A("j")
h = B("h")
d = C("d")
c = B("c")
g = C("g")

j.r = d
j.t = h
h.u = j
h.q = c
d.x = g
c.u = j
c.q = h
g.x = d
assert j.t.q.u.r.txt == "d"