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

class B:
    def __init__(self, txt: str):
        self.v: C = None
        self.y: D = None
        self.r: C = None
        self.t: 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.w: B = None
        self.txt = txt

g = A("g")
d = B("d")
a = C("a")
f = D("f")
h = C("h")
e = C("e")

g.q = d
d.v = a
d.y = f
d.t = f
d.r = e
a.x = g
f.w = d
h.x = g
e.x = g
assert f.w.r.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: C = None
        self.y: D = None
        self.r: C = None
        self.t: 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.w: B = None
        self.txt = txt

g = A("g")
d = B("d")
a = C("a")
f = D("f")
h = C("h")
e = C("e")

g.q = d
d.v = a
d.y = f
d.t = f
d.r = e
a.x = g
f.w = d
h.x = g
e.x = g
assert f.w.r.x.q.txt == "d"