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

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

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

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

l = A("l")
g = B("g")
i = C("i")
d = D("d")

l.y = i
l.p = i
l.w = d
l.u = d
g.s = l
g.w = l
g.r = l
g.q = d
i.x = l
d.u = g
assert l.w.u.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.w: D = None
        self.u: D = None
        self.p: C = None
        self.txt = txt

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

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

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

l = A("l")
g = B("g")
i = C("i")
d = D("d")

l.y = i
l.p = i
l.w = d
l.u = d
g.s = l
g.w = l
g.r = l
g.q = d
i.x = l
d.u = g
assert l.w.u.q.u.txt == "g"