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

class B:
    def __init__(self, txt: str):
        self.x: D = 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.r: A = None
        self.x: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.z: C = None
        self.u: B = None
        self.txt = txt

class F:
    def __init__(self, txt: str):
        self.v: D = None
        self.r: A = None
        self.y: A = None
        self.z: A = None
        self.p: C = None
        self.txt = txt

l = A("l")
g = B("g")
m = C("m")
d = D("d")
c = E("c")
i = F("i")
j = A("j")

l.r = g
g.x = d
m.t = j
d.r = j
d.x = m
c.z = m
c.u = g
i.v = d
i.r = j
i.y = j
i.z = j
i.p = m
j.r = g
assert l.r.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.x: D = 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.r: A = None
        self.x: C = None
        self.txt = txt

class E:
    def __init__(self, txt: str):
        self.z: C = None
        self.u: B = None
        self.txt = txt

class F:
    def __init__(self, txt: str):
        self.v: D = None
        self.r: A = None
        self.y: A = None
        self.z: A = None
        self.p: C = None
        self.txt = txt

l = A("l")
g = B("g")
m = C("m")
d = D("d")
c = E("c")
i = F("i")
j = A("j")

l.r = g
g.x = d
m.t = j
d.r = j
d.x = m
c.z = m
c.u = g
i.v = d
i.r = j
i.y = j
i.z = j
i.p = m
j.r = g
assert l.r.x.r.r.txt == "g"