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

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

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

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

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

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

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

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

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

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

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