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

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

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

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

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

h.o = a
h.q = e
f.s = e
f.p = h
e.v = a
e.w = a
a.v = h
a.q = f
assert f.p.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.q: C = None
        self.txt = txt

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

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

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

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

h.o = a
h.q = e
f.s = e
f.p = h
e.v = a
e.w = a
a.v = h
a.q = f
assert f.p.o.q.txt == "f"