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

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

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

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

j.w = c
j.p = c
j.q = a
c.u = d
d.u = c
a.w = c
a.p = c
a.q = j
assert c.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.p: B = None
        self.q: A = None
        self.txt = txt

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

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

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

j.w = c
j.p = c
j.q = a
c.u = d
d.u = c
a.w = c
a.p = c
a.q = j
assert c.u.u.u.txt == "d"