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

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

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

a = A("a")
g = B("g")
j = C("j")
l = C("l")

a.r = g
g.x = a
j.u = a
j.w = a
j.y = l
l.u = a
l.w = a
l.y = j
assert j.w.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

a = A("a")
g = B("g")
j = C("j")
l = C("l")

a.r = g
g.x = a
j.u = a
j.w = a
j.y = l
l.u = a
l.w = a
l.y = j
assert j.w.r.x.r.txt == "g"