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

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

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

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

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

g.t = h
k.p = g
f.t = g
h.u = f
h.r = k
h.x = g
i.p = g
assert f.t.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

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

g.t = h
k.p = g
f.t = g
h.u = f
h.r = k
h.x = g
i.p = g
assert f.t.t.x.txt == "g"