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

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

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

class D:
    def __init__(self, txt: str):
        self.y: D = None
        self.s: C = None
        self.txt = txt

b = A("b")
c = B("c")
h = C("h")
j = D("j")
d = D("d")
f = C("f")

b.w = f
b.o = h
c.z = h
c.q = h
c.x = f
h.v = f
h.q = b
h.x = b
j.y = d
j.s = h
d.y = j
d.s = h
f.v = h
f.q = b
f.x = b
assert h.v.q.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.o: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.y: D = None
        self.s: C = None
        self.txt = txt

b = A("b")
c = B("c")
h = C("h")
j = D("j")
d = D("d")
f = C("f")

b.w = f
b.o = h
c.z = h
c.q = h
c.x = f
h.v = f
h.q = b
h.x = b
j.y = d
j.s = h
d.y = j
d.s = h
f.v = h
f.q = b
f.x = b
assert h.v.q.o.v.txt == "f"