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

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

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

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

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

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

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

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

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