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

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

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

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

f.u = c
d.x = a
i.p = d
i.u = j
i.q = j
c.p = e
c.u = f
c.q = f
a.p = d
a.u = f
a.q = j
e.x = i
j.u = i
assert j.u.q.u.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

f.u = c
d.x = a
i.p = d
i.u = j
i.q = j
c.p = e
c.u = f
c.q = f
a.p = d
a.u = f
a.q = j
e.x = i
j.u = i
assert j.u.q.u.p.x.txt == "a"