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

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

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

d = A("d")
e = B("e")
j = C("j")
k = C("k")
i = C("i")
c = B("c")

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

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

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

d = A("d")
e = B("e")
j = C("j")
k = C("k")
i = C("i")
c = B("c")

d.s = e
e.x = d
e.w = c
e.p = j
j.w = c
j.q = i
j.r = d
k.w = e
k.q = i
k.r = d
i.w = c
i.q = k
i.r = d
c.x = d
c.w = e
c.p = j
assert c.p.w.p.w.txt == "c"