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

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

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

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

d = A("d")
j = B("j")
b = C("b")
h = D("h")
g = C("g")
a = B("a")

d.t = a
j.q = a
j.y = b
b.r = h
b.v = d
b.p = j
h.s = a
h.q = d
g.r = h
g.v = d
g.p = j
a.q = j
a.y = g
assert h.s.y.v.t.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

d = A("d")
j = B("j")
b = C("b")
h = D("h")
g = C("g")
a = B("a")

d.t = a
j.q = a
j.y = b
b.r = h
b.v = d
b.p = j
h.s = a
h.q = d
g.r = h
g.v = d
g.p = j
a.q = j
a.y = g
assert h.s.y.v.t.y.v.txt == "d"