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

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

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

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

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

j.s = h
j.v = f
j.q = f
j.p = b
n.o = b
b.p = j
h.r = b
f.s = h
f.v = j
f.q = j
f.p = b
assert h.r.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.v: A = None
        self.p: C = None
        self.q: A = None
        self.txt = txt

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

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

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

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

j.s = h
j.v = f
j.q = f
j.p = b
n.o = b
b.p = j
h.r = b
f.s = h
f.v = j
f.q = j
f.p = b
assert h.r.p.v.txt == "f"