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

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

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

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

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

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

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

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

h.p = j
j.w = g
g.x = j
g.q = h
assert h.p.w.x.txt == "j"