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

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

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

i = A("i")
d = B("d")
c = C("c")
g = C("g")
a = A("a")

i.p = a
i.r = a
i.u = a
d.v = c
c.w = a
c.q = a
g.w = i
g.q = i
a.p = i
a.r = i
a.u = i
assert c.q.r.p.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: A = None
        self.u: A = None
        self.txt = txt

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

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

i = A("i")
d = B("d")
c = C("c")
g = C("g")
a = A("a")

i.p = a
i.r = a
i.u = a
d.v = c
c.w = a
c.q = a
g.w = i
g.q = i
a.p = i
a.r = i
a.u = i
assert c.q.r.p.r.u.txt == "a"