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

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

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

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

g = A("g")
d = B("d")
l = C("l")
m = D("m")
b = A("b")
n = D("n")

g.q = d
g.s = d
g.t = m
g.w = l
d.x = b
d.z = l
l.t = b
l.p = d
m.r = b
m.w = d
m.p = g
b.q = d
b.s = d
b.t = m
b.w = l
n.r = b
n.w = d
n.p = g
assert l.p.z.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: D = None
        self.w: C = None
        self.s: B = None
        self.txt = txt

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

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

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

g = A("g")
d = B("d")
l = C("l")
m = D("m")
b = A("b")
n = D("n")

g.q = d
g.s = d
g.t = m
g.w = l
d.x = b
d.z = l
l.t = b
l.p = d
m.r = b
m.w = d
m.p = g
b.q = d
b.s = d
b.t = m
b.w = l
n.r = b
n.w = d
n.p = g
assert l.p.z.t.q.txt == "d"