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

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

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

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

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

b.p = k
h.z = f
d.v = b
d.s = f
d.x = k
f.t = h
f.x = d
f.z = k
k.p = b
assert b.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

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

b.p = k
h.z = f
d.v = b
d.s = f
d.x = k
f.t = h
f.x = d
f.z = k
k.p = b
assert b.p.p.p.p.txt == "b"