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

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

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

d = A("d")
b = B("b")
g = C("g")
f = B("f")
k = C("k")
l = B("l")
a = A("a")

d.x = k
d.w = a
b.r = l
g.u = a
g.r = a
g.q = b
f.r = b
k.u = a
k.r = a
k.q = b
l.r = b
a.x = k
a.w = d
assert b.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.w: A = None
        self.txt = txt

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

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

d = A("d")
b = B("b")
g = C("g")
f = B("f")
k = C("k")
l = B("l")
a = A("a")

d.x = k
d.w = a
b.r = l
g.u = a
g.r = a
g.q = b
f.r = b
k.u = a
k.r = a
k.q = b
l.r = b
a.x = k
a.w = d
assert b.r.r.r.txt == "l"