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

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

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

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

b = A("b")
g = B("g")
f = C("f")
l = D("l")
j = B("j")
m = B("m")
i = C("i")

b.z = f
b.q = j
g.v = j
f.x = i
f.p = i
f.z = b
f.y = b
l.x = b
l.p = g
l.y = f
j.v = m
m.v = j
i.x = f
i.p = f
i.z = b
i.y = b
assert i.p.y.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.q: B = None
        self.txt = txt

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

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

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

b = A("b")
g = B("g")
f = C("f")
l = D("l")
j = B("j")
m = B("m")
i = C("i")

b.z = f
b.q = j
g.v = j
f.x = i
f.p = i
f.z = b
f.y = b
l.x = b
l.p = g
l.y = f
j.v = m
m.v = j
i.x = f
i.p = f
i.z = b
i.y = b
assert i.p.y.z.z.z.txt == "f"