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

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

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

f = A("f")
d = B("d")
j = C("j")
m = A("m")
k = B("k")

f.x = j
f.w = d
d.x = j
d.q = j
d.u = k
j.r = d
m.x = j
m.w = k
k.x = j
k.q = j
k.u = d
assert k.u.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.w: B = None
        self.txt = txt

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

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

f = A("f")
d = B("d")
j = C("j")
m = A("m")
k = B("k")

f.x = j
f.w = d
d.x = j
d.q = j
d.u = k
j.r = d
m.x = j
m.w = k
k.x = j
k.q = j
k.u = d
assert k.u.q.r.txt == "d"