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

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

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

n = A("n")
f = B("f")
h = C("h")

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

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

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

n = A("n")
f = B("f")
h = C("h")

n.q = f
n.p = f
f.x = n
f.y = h
h.p = n
assert h.p.q.x.txt == "n"