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

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

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

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

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

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

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

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

j.p = g
j.r = h
j.q = i
i.y = g
i.s = j
g.w = h
h.y = g
h.s = j
assert j.r.y.w.y.txt == "g"