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

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

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

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

h = A("h")
d = B("d")
n = C("n")
f = D("f")
c = C("c")

h.q = f
h.y = d
d.y = f
n.y = h
n.w = f
f.r = c
f.w = h
c.y = h
c.w = f
assert d.y.w.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.y: B = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
n = C("n")
f = D("f")
c = C("c")

h.q = f
h.y = d
d.y = f
n.y = h
n.w = f
f.r = c
f.w = h
c.y = h
c.w = f
assert d.y.w.y.y.txt == "f"