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

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

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

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

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

d.q = n
n.p = d
n.t = h
h.x = n
h.t = c
c.t = d
assert d.q.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

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

d.q = n
n.p = d
n.t = h
h.x = n
h.t = c
c.t = d
assert d.q.t.t.txt == "c"