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

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

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

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

f = A("f")
j = B("j")
i = C("i")
k = D("k")
b = A("b")

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

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

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

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

f = A("f")
j = B("j")
i = C("i")
k = D("k")
b = A("b")

f.p = b
f.s = k
j.q = b
j.z = k
i.v = j
i.q = b
i.r = b
k.o = b
b.p = f
b.s = k
assert i.v.q.p.p.p.txt == "f"