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

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

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

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

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

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

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

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

g.p = n
g.w = n
g.y = h
n.y = j
j.q = n
h.p = n
h.w = n
h.y = g
assert g.w.y.q.txt == "n"