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

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

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

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

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

b.q = h
b.z = g
b.x = g
h.t = i
h.q = g
g.p = h
g.r = i
c.r = h
i.p = h
i.r = g
assert i.p.q.p.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: C = None
        self.x: C = None
        self.txt = txt

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

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

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

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

b.q = h
b.z = g
b.x = g
h.t = i
h.q = g
g.p = h
g.r = i
c.r = h
i.p = h
i.r = g
assert i.p.q.p.t.r.txt == "g"