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

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

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

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

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

g.q = h
g.t = b
g.x = b
b.p = f
f.r = b
h.t = b
h.v = b
h.u = g
h.y = c
c.t = b
c.v = b
c.u = g
c.y = h
assert f.r.p.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.t: B = None
        self.x: B = None
        self.txt = txt

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

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

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

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

g.q = h
g.t = b
g.x = b
b.p = f
f.r = b
h.t = b
h.v = b
h.u = g
h.y = c
c.t = b
c.v = b
c.u = g
c.y = h
assert f.r.p.r.p.r.txt == "b"