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

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

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

b = A("b")
j = B("j")
c = C("c")
d = B("d")

b.q = d
j.p = c
j.x = b
c.s = b
c.p = b
d.p = c
d.x = b
assert c.p.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

b = A("b")
j = B("j")
c = C("c")
d = B("d")

b.q = d
j.p = c
j.x = b
c.s = b
c.p = b
d.p = c
d.x = b
assert c.p.q.p.txt == "c"