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

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

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

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

g = A("g")
h = B("h")
i = C("i")
b = D("b")
c = D("c")
f = A("f")
k = B("k")

g.y = f
g.v = i
h.w = i
h.y = b
h.o = k
i.y = k
i.v = g
i.q = h
b.z = c
b.v = c
b.p = i
c.z = b
c.v = b
c.p = i
f.y = g
f.v = i
k.w = i
k.y = b
k.o = h
assert b.z.z.p.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.v: C = None
        self.txt = txt

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

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

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

g = A("g")
h = B("h")
i = C("i")
b = D("b")
c = D("c")
f = A("f")
k = B("k")

g.y = f
g.v = i
h.w = i
h.y = b
h.o = k
i.y = k
i.v = g
i.q = h
b.z = c
b.v = c
b.p = i
c.z = b
c.v = b
c.p = i
f.y = g
f.v = i
k.w = i
k.y = b
k.o = h
assert b.z.z.p.y.y.txt == "b"