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

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

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

j = A("j")
a = B("a")
g = C("g")
d = B("d")
k = B("k")

j.r = k
j.s = d
a.u = g
a.p = j
g.w = j
d.u = g
d.p = j
k.u = g
k.p = j
assert j.r.u.w.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.s: B = None
        self.txt = txt

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

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

j = A("j")
a = B("a")
g = C("g")
d = B("d")
k = B("k")

j.r = k
j.s = d
a.u = g
a.p = j
g.w = j
d.u = g
d.p = j
k.u = g
k.p = j
assert j.r.u.w.r.u.txt == "g"