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

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

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

n = A("n")
b = B("b")
g = C("g")
c = A("c")
f = B("f")
d = B("d")

n.x = c
b.p = g
g.q = f
c.x = n
f.p = g
d.p = g
assert c.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

n = A("n")
b = B("b")
g = C("g")
c = A("c")
f = B("f")
d = B("d")

n.x = c
b.p = g
g.q = f
c.x = n
f.p = g
d.p = g
assert c.x.x.x.x.x.txt == "n"