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

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

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

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

c = A("c")
a = B("a")
m = C("m")
f = D("f")
i = C("i")
b = A("b")
h = D("h")

c.y = a
c.q = a
c.r = i
a.r = b
m.s = a
m.y = f
m.t = b
m.z = b
f.p = m
f.q = b
i.s = a
i.y = f
i.t = b
i.z = c
b.y = a
b.q = a
b.r = m
h.p = m
h.q = b
assert f.q.r.s.r.r.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.r: C = None
        self.txt = txt

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

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

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

c = A("c")
a = B("a")
m = C("m")
f = D("f")
i = C("i")
b = A("b")
h = D("h")

c.y = a
c.q = a
c.r = i
a.r = b
m.s = a
m.y = f
m.t = b
m.z = b
f.p = m
f.q = b
i.s = a
i.y = f
i.t = b
i.z = c
b.y = a
b.q = a
b.r = m
h.p = m
h.q = b
assert f.q.r.s.r.r.y.q.txt == "b"