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

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

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

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

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

d.v = j
d.r = n
d.y = a
b.x = d
b.r = d
b.q = a
n.w = h
n.x = j
h.r = j
h.v = j
h.w = d
a.x = d
a.r = d
a.q = b
j.w = h
j.x = n
assert h.w.y.x.y.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.r: C = None
        self.y: B = None
        self.txt = txt

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

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

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

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

d.v = j
d.r = n
d.y = a
b.x = d
b.r = d
b.q = a
n.w = h
n.x = j
h.r = j
h.v = j
h.w = d
a.x = d
a.r = d
a.q = b
j.w = h
j.x = n
assert h.w.y.x.y.q.x.txt == "d"